Class: Puncher

Inherits:
FSEvent
  • Object
show all
Defined in:
lib/puncher.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, files) ⇒ Puncher

Returns a new instance of Puncher.



10
11
12
13
14
# File 'lib/puncher.rb', line 10

def initialize(command, files)
  @command, @files, @latency, @last_sec = command, files, 0.2, Time.now

  start
end

Instance Method Details

#on_change(directories) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/puncher.rb', line 21

def on_change(directories)
  time = @last_sec

  @files.each { |f| @last_sec = File.mtime(f) if File.mtime(f) > @last_sec }

  system @command unless time == @last_sec
end

#startObject



16
17
18
19
# File 'lib/puncher.rb', line 16

def start
  watch_directories((@files.collect { |f| File.dirname(f) }).uniq)
  super
end