Class: Script::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/watch.rb

Instance Method Summary collapse

Constructor Details

#initialize(toplevel, filename, &block) ⇒ Watch



10
11
12
13
14
15
# File 'lib/plugins/watch.rb', line 10

def initialize(toplevel, filename, &block)
  @toplevel = toplevel
  @filename = filename
  @notifier = INotify::Notifier.new
  instance_eval(&block)
end

Instance Method Details

#doitObject



17
18
19
20
21
22
# File 'lib/plugins/watch.rb', line 17

def doit
  @notifier.to_io.tap do |io|
    rs, = IO.select([io], nil, nil, 0)
    @notifier.process if rs
  end
end

#modify(&block) ⇒ Object


DSL



26
27
28
29
30
31
# File 'lib/plugins/watch.rb', line 26

def modify(&block)
  @modify = Prog.new(@toplevel, &block)
  @notifier.watch(@filename, :modify) do
    @modify.doit
  end
end