Search code examples
ruby-on-railsguardgrowl

Running gntp only on certain development VMs


I'm doing Rails development on a virtual machine setup that's somewhat similar to Vagrant. What I like the most about it is that it's portable so I have basically the same Ubuntu based virtual machine at home and at work - I made a copy of it at a given moment.

My problem is that I have set up guard to notify Growl on my Mac at home, however since I'm on Windows at work I would like to disable the notification feature on the VM running on the Windows host.

Here's the line in question in my Guardfile.

notification :gntp, :host => '192.168.1.139'

Any ideas on how to disable this on one of the VMs?

From the top of my head, one thing that's different on the two VMs is the IP address but I guess I could also modify the hostname.

UPDATE

I half solved this, by modifying the above line to:

notification :gntp, :host => '192.168.1.139' if Socket.gethostname == 'railsbox'
# 'railsbox' is the VM on my Mac, I renamed the VM on Windows to 'railsbox-win'

At least this way it doesn't try to notify that IP address but tries localhost (which is the default behaviour). I still get an error at the end of each spec run but at least it won't hang for precious seconds. The error is:

ERROR - Error sending notification with gntp: Connection refused - connect(2)

The question becomes how to completely disable gntp on the VM running on Windows?


Solution

  • The reason why you're getting an error in the second case is that, Guard automatically selects an available notifier by going through the installed ones on your box(es). So, one way to get the functionality you want is to create two separate environments.

    Say, macdev and windev on your computer and the windows machine respectively, and in your Gemfile, you'd add the gntp gem only in the group :macdev {..} part. More on creating custom environments in Rails: http://railscasts.com/episodes/72-adding-an-environment

    # Gemfile
    
    group :macdev do
      gem 'ruby_gntp'
    end
    
    group :windev do
      # a windows-specific notification gem, may be.
    end
    

    This should fix it.

    Alternatively, create an environment variable for each of the VMs:

    # On Mac
    export VM = "mac"
    # and a similar command on windows.
    

    And in your Guardfile,

    # Guardfile
    
    notification :off if ENV['VM'] == "win"
    notification :gntp, :host => '192.168.1.139' if ENV['VM'] == "mac"