Class: ChangeListener

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, *arguments) ⇒ ChangeListener

Returns a new instance of ChangeListener.



9
10
11
12
13
14
15
# File 'lib/change_listener.rb', line 9

def initialize(command, *arguments)
  @command   = command
  @arguments = arguments
  @listener  = Listen.to('./').ignore(/^\.\w+/)
  
  @listener.change{ execute }
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



7
8
9
# File 'lib/change_listener.rb', line 7

def arguments
  @arguments
end

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

#listenerObject (readonly)

Returns the value of attribute listener.



5
6
7
# File 'lib/change_listener.rb', line 5

def listener
  @listener
end

Instance Method Details

#executeObject



21
22
23
24
25
# File 'lib/change_listener.rb', line 21

def execute
  listener.pause
  Kernel.system(ENV, command, *arguments)
  listener.unpause
end

#ignore(*regexps) ⇒ Object



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

def ignore(*regexps)
  @listener.ignore(*regexps)
end

#ignore_path(*paths) ⇒ Object



31
32
33
34
35
# File 'lib/change_listener.rb', line 31

def ignore_path(*paths)
  globs = paths.map{|p| FileGlob.new(p)}
  
  @listener.ignore(*globs)
end

#startObject



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

def start
  listener.start(false)
end