Skip to content

Commit

Permalink
Merge pull request #203 from guard/env_notifications
Browse files Browse the repository at this point in the history
Use ENV variable to store Notifier notifications
  • Loading branch information
thibaudgg committed Dec 25, 2011
2 parents 2f86735 + cfc49e8 commit 2614b44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/guard/dsl.rb
Expand Up @@ -109,7 +109,7 @@ def evaluate_guardfile(options = {})
def reevaluate_guardfile
::Guard.guards.clear
::Guard.reset_groups
::Guard::Notifier.notifications.clear
::Guard::Notifier.clear_notifications
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
msg = 'Guardfile has been re-evaluated.'
Expand Down
14 changes: 11 additions & 3 deletions lib/guard/notifier.rb
@@ -1,3 +1,5 @@
require 'yaml'

require 'rbconfig'
require 'pathname'
require 'guard/ui'
Expand Down Expand Up @@ -53,15 +55,21 @@ module Notifier
# @return [Hash] the notifications
#
def notifications
@notifications ||= []
ENV['GUARD_NOTIFICATIONS'] ? YAML::load(ENV['GUARD_NOTIFICATIONS']) : []
end

# Set the available notifications.
#
# @param [Array<Hash>] notifications the notifications
#
def notifications=(notifications)
@notifications = notifications
ENV['GUARD_NOTIFICATIONS'] = YAML::dump(notifications)
end

# Clear available notifications.
#
def clear_notifications
ENV['GUARD_NOTIFICATIONS'] = nil
end

# Turn notifications on. If no notifications are defined
Expand Down Expand Up @@ -107,7 +115,7 @@ def add_notification(name, options = { }, silent = false)
return turn_off if name == :off

if NOTIFIERS.has_key?(name) && NOTIFIERS[name].available?(silent)
notifications << { :name => name, :options => options }
self.notifications = notifications << { :name => name, :options => options }
true
else
false
Expand Down

0 comments on commit 2614b44

Please sign in to comment.