Class: Ichiban::Watcher
- Inherits:
-
Object
- Object
- Ichiban::Watcher
- Defined in:
- lib/ichiban/watcher.rb
Instance Attribute Summary collapse
-
#listen_event_log ⇒ Object
readonly
Returns the value of attribute listen_event_log.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Watcher
constructor
A new instance of Watcher.
-
#on_change(modified, added, deleted) ⇒ Object
The test suite calls this method directly to bypass the Listen gem for certain tests.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#listen_event_log ⇒ Object (readonly)
Returns the value of attribute listen_event_log.
13 14 15 |
# File 'lib/ichiban/watcher.rb', line 13 def listen_event_log @listen_event_log end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
11 12 13 |
# File 'lib/ichiban/watcher.rb', line 11 def listener @listener end |
Instance Method Details
#on_change(modified, added, deleted) ⇒ Object
The test suite calls this method directly to bypass the Listen gem for certain tests.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ichiban/watcher.rb', line 17 def on_change(modified, added, deleted) # Modifications and additions are treated the same. (modified + added).uniq.each do |path| if file = Ichiban::ProjectFile.from_abs(path) begin @loader.change(file) # Tell the Loader that this file has changed file.update rescue Exception => exc Ichiban.logger.exception(exc) end end end # Deletions are handled specially. deleted.each do |path| Ichiban::Deleter.new.delete_dest(path) end # Finally, propagate this change to any dependent files. (modified + added + deleted).uniq.each do |path| begin Ichiban::Dependencies.propagate(path) rescue => exc Ichiban.logger.exception(exc) end end end |
#start ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ichiban/watcher.rb', line 45 def start Ichiban.logger.out 'Starting watcher' begin @listener = Listen.to( Ichiban.project_root, ignore: /.listen_test$/, latency: @options[:latency] ) do |modified, added, deleted| @listen_event_log << [modified, added, deleted] on_change modified, added, deleted end @listener.start sleep rescue Interrupt stop exit 0 end end |