Class: FSSMGuard

Inherits:
Object
  • Object
show all
Defined in:
lib/workpile/cli.rb

Direct Known Subclasses

RSpecGuard

Instance Method Summary collapse

Constructor Details

#initializeFSSMGuard

Returns a new instance of FSSMGuard.



9
10
11
# File 'lib/workpile/cli.rb', line 9

def initialize
  @watch = {}
end

Instance Method Details

#event(base, relative) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/workpile/cli.rb', line 31

def event(base, relative)
  @watch.keys.each do |regexp|
    if m = ( relative.match(regexp) )
      invoke(@watch[regexp] ? @watch[regexp].call(m) : relative)
    end
  end
end

#guard(&proc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/workpile/cli.rb', line 13

def guard(&proc)
  instance_exec &proc
  _self = self
  Thread.new do
    FSSM.monitor(".") do
      update{|base,relative| _self.event(base,relative); }
      delete{|base,relative| _self.event(base,relative); }
      create{|base,relative| _self.event(base,relative); }
    end
  end
  $stdin.gets
  on_exit
end

#invoke(fname) ⇒ Object



39
40
41
# File 'lib/workpile/cli.rb', line 39

def invoke(fname)
  system(fname)
end

#on_exitObject



43
44
# File 'lib/workpile/cli.rb', line 43

def on_exit
end

#watch(regexp, &block) ⇒ Object



27
28
29
# File 'lib/workpile/cli.rb', line 27

def watch(regexp, &block)
  @watch[regexp] = block
end