Class: Sublayer::Triggers::FileChange

Inherits:
Base
  • Object
show all
Defined in:
lib/sublayer/triggers/file_change.rb

Instance Method Summary collapse

Methods inherited from Base

#activate

Constructor Details

#initialize(&block) ⇒ FileChange

Returns a new instance of FileChange.



4
5
6
# File 'lib/sublayer/triggers/file_change.rb', line 4

def initialize(&block)
  @block = block
end

Instance Method Details

#setup(agent) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/sublayer/triggers/file_change.rb', line 8

def setup(agent)
  files_to_watch = agent.instance_eval(&@block)
  folders = files_to_watch.map { |file| File.dirname(File.expand_path(file)) }.uniq

  Listen.to(*folders) do |modified, added, removed|
    if files_to_watch.any? { |file| modified.include?(File.expand_path(file)) }
      activate(agent)
    end
  end.start
end