Class: Lather::Watcher
- Inherits:
-
Object
- Object
- Lather::Watcher
- Defined in:
- lib/lather/watcher.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #go! ⇒ Object
-
#initialize(*globs, &callback) ⇒ Watcher
constructor
A new instance of Watcher.
Constructor Details
#initialize(*globs, &callback) ⇒ Watcher
Returns a new instance of Watcher.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/lather/watcher.rb', line 6 def initialize *globs, &callback raise ArgumentError, "need a callback" unless block_given? @callback = callback @options = { :force => false, :sleep => 1 } @options.merge!(globs.pop) if globs.last.is_a? Hash @globs = globs.flatten @files = find_files end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/lather/watcher.rb', line 3 def files @files end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/lather/watcher.rb', line 4 def @options end |
Instance Method Details
#go! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lather/watcher.rb', line 17 def go! @timestamp = Time.now @callback[@files.keys] if @options[:force] loop do unless (changed = ).empty? @callback[changed] end Kernel.sleep @options[:sleep] end end |