Class: Listen::MultiListener
- Defined in:
- lib/listen/multi_listener.rb
Constant Summary
Constants inherited from Listener
Listener::DEFAULT_TO_RELATIVE_PATHS
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
-
#directories_records ⇒ Object
readonly
Returns the value of attribute directories_records.
Attributes inherited from Listener
Instance Method Summary collapse
-
#filter(*regexps) ⇒ Listen::Listener
Adds file filters to the listener.
-
#filter!(*regexps) ⇒ Listen::Listener
Replaces file filters in the listener.
-
#ignore(*paths) ⇒ Listen::Listener
Adds ignored paths to the listener.
-
#ignore!(*paths) ⇒ Listen::Listener
Replaces ignored paths in the listener.
-
#initialize(*args) {|modified, added, removed| ... } ⇒ MultiListener
constructor
Initializes the multiple directories listener.
-
#on_change(directories_to_search, options = {}) ⇒ Object
Runs the callback passing it the changes if there are any.
-
#start(blocking = true) ⇒ Object
Starts the listener by initializing the adapter and building the directory record concurrently, then it starts the adapter to watch for changes.
-
#unpause ⇒ Listen::Listener
Unpauses the listener.
Methods inherited from Listener
#change, #force_polling, #latency, #pause, #paused?, #polling_fallback_message, #relative_paths, #stop
Constructor Details
#initialize(*args) {|modified, added, removed| ... } ⇒ MultiListener
Initializes the multiple directories listener.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/listen/multi_listener.rb', line 20 def initialize(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} directories = args @block = block @directories = directories.map { |d| Pathname.new(d).realpath.to_s } @directories_records = @directories.map { |d| DirectoryRecord.new(d) } ignore(*.delete(:ignore)) if [:ignore] filter(*.delete(:filter)) if [:filter] @adapter_options = end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/listen/multi_listener.rb', line 3 def adapter @adapter end |
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
3 4 5 |
# File 'lib/listen/multi_listener.rb', line 3 def directories @directories end |
#directories_records ⇒ Object (readonly)
Returns the value of attribute directories_records.
3 4 5 |
# File 'lib/listen/multi_listener.rb', line 3 def directories_records @directories_records end |
Instance Method Details
#filter(*regexps) ⇒ Listen::Listener
Adds file filters to the listener.
85 86 87 88 |
# File 'lib/listen/multi_listener.rb', line 85 def filter(*regexps) @directories_records.each { |r| r.filter(*regexps) } self end |
#filter!(*regexps) ⇒ Listen::Listener
Replaces file filters in the listener.
96 97 98 99 |
# File 'lib/listen/multi_listener.rb', line 96 def filter!(*regexps) @directories_records.each { |r| r.filter!(*regexps) } self end |
#ignore(*paths) ⇒ Listen::Listener
Adds ignored paths to the listener.
63 64 65 66 |
# File 'lib/listen/multi_listener.rb', line 63 def ignore(*paths) @directories_records.each { |r| r.ignore(*paths) } self end |
#ignore!(*paths) ⇒ Listen::Listener
Replaces ignored paths in the listener.
74 75 76 77 |
# File 'lib/listen/multi_listener.rb', line 74 def ignore!(*paths) @directories_records.each { |r| r.ignore!(*paths) } self end |
#on_change(directories_to_search, options = {}) ⇒ Object
Runs the callback passing it the changes if there are any.
105 106 107 108 109 110 |
# File 'lib/listen/multi_listener.rb', line 105 def on_change(directories_to_search, = {}) changes = fetch_records_changes(directories_to_search, ) unless changes.values.all? { |paths| paths.empty? } @block.call(changes[:modified],changes[:added],changes[:removed]) end end |
#start(blocking = true) ⇒ Object
Starts the listener by initializing the adapter and building the directory record concurrently, then it starts the adapter to watch for changes.
40 41 42 43 44 45 |
# File 'lib/listen/multi_listener.rb', line 40 def start(blocking = true) t = Thread.new { @directories_records.each { |r| r.build } } @adapter = initialize_adapter t.join @adapter.start(blocking) end |
#unpause ⇒ Listen::Listener
Unpauses the listener.
51 52 53 54 55 |
# File 'lib/listen/multi_listener.rb', line 51 def unpause @directories_records.each { |r| r.build } @adapter.paused = false self end |