Search code examples
rubyrubygemsguard

Can I setup guard gem in ruby to notify me in GNU screen instead of libnotify?


I'm I'm following the rails tutorial but I'm doing it on the server. Now, I'm using Guard gem to monitor my changes and execute tests. From what I see, it would usually use libnotify to notify me if the test failed or succeeded.

Now, I want it to notify me on my GNU screen instance instead.

Is there a way to do it at all? From this link (documentation for Guard) I'm not sure, but me being a ruby beginner, I need to ask anyway.


Solution

  • Writing a Guard notifier would be a good exercise for a prospective Ruby developer.

    First you fork Guard, clone the project and create a new notifier in lib/guard/notifiers/screen.rb like:

    module Guard
      module Notifier
        module Growl
          extend self
    
          def available?(silent = false)
          end
    
          def notify(type, title, message, image, options = { })
          end
    
        end
      end
    end
    

    Now you only have to implement the two methods:

    1. available? for checking the environment, libraries and external commands
    2. notify for doing the actual notification

    Have a look at the Growl notifier for an API notifier and Notifysend for an external program notifier. If you look closer at these modules, you'll see that most stuff is documentation and initialization, the notification code itself is merely small.

    You can try your Guard by using it from another project by adding it to your projects Gemfile:

    group :development do
      gem 'guard', path => '/home/you/code/guard'
    end
    

    You can also open a pull request before you finished and the Guard core team will help you and guide you through the stuff that needs to be done before it can be merged, for example specs and documentation.