Class: Guard::Pusher

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/pusher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Pusher

Returns a new instance of Pusher.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/guard/pusher.rb', line 22

def initialize(watchers = [], options = {})
  super

  @options = options

  config = if File.file?('config/pusher.yml')
    YAML.load(ERB.new(File.read('config/pusher.yml')).result)['development']
  else
    options
  end

  if self.class.configure(config)
    UI.info('Pusher is ready.', :reset => true)
  else
    UI.info("D'oh! Pusher not properly configured. Make sure to add app_id, key and secret.", :reset => true)
  end
end

Class Method Details

.configure(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/guard/pusher.rb', line 9

def self.configure(options)
  %w{app_id key secret}.inject(Hash.new) { |hash, key|
    hash[key] = options[key] || options[key.to_sym]
    hash
  }.each { |config, value|
    ::Pusher.send("#{config}=", value)
  }

  ::Pusher['guard-pusher']

  rescue ::Pusher::ConfigurationError
end

Instance Method Details

#run_on_changes(paths) ⇒ Object



40
41
42
# File 'lib/guard/pusher.rb', line 40

def run_on_changes(paths)
  ::Pusher['guard-pusher'].trigger(@options[:event] || 'guard', { :paths => paths })
end