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.



6
7
8
# File 'lib/workpile/cli.rb', line 6

def initialize
  @watch = {}
end

Instance Method Details

#event(base, relative) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/workpile/cli.rb', line 28

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

#guard(&proc) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/workpile/cli.rb', line 10

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



36
37
38
# File 'lib/workpile/cli.rb', line 36

def invoke(fname)
  system(fname)
end

#on_exitObject



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

def on_exit
end

#watch(regexp, &block) ⇒ Object



24
25
26
# File 'lib/workpile/cli.rb', line 24

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