Class: Lookbook::FileWatcher
- Inherits:
-
Object
- Object
- Lookbook::FileWatcher
- Defined in:
- lib/lookbook/file_watcher.rb
Instance Attribute Summary collapse
-
#force_polling ⇒ Object
readonly
Returns the value of attribute force_polling.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
Instance Method Summary collapse
-
#initialize(force_polling: false) ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #start ⇒ Object
- #stop ⇒ Object
- #watch(paths, extensions = ".*", opts = nil, &block) ⇒ Object
Constructor Details
#initialize(force_polling: false) ⇒ FileWatcher
Returns a new instance of FileWatcher.
5 6 7 8 |
# File 'lib/lookbook/file_watcher.rb', line 5 def initialize(force_polling: false) @force_polling = force_polling @listeners = [] end |
Instance Attribute Details
#force_polling ⇒ Object (readonly)
Returns the value of attribute force_polling.
3 4 5 |
# File 'lib/lookbook/file_watcher.rb', line 3 def force_polling @force_polling end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
3 4 5 |
# File 'lib/lookbook/file_watcher.rb', line 3 def listeners @listeners end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 |
# File 'lib/lookbook/file_watcher.rb', line 21 def start if listeners.any? Lookbook.logger.debug "Starting listeners" listeners.each { |l| l.start } end end |
#stop ⇒ Object
28 29 30 31 32 33 |
# File 'lib/lookbook/file_watcher.rb', line 28 def stop if listeners.any? Lookbook.logger.debug "Stopping listeners" listeners.each { |l| l.stop } end end |
#watch(paths, extensions = ".*", opts = nil, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lookbook/file_watcher.rb', line 10 def watch(paths, extensions = ".*", opts = nil, &block) paths = PathUtils.normalize_paths(paths) if paths.any? opts = opts.to_h opts[:only] = /\.(#{Array(extensions).join("|")})$/ listeners << init_listener(paths, opts, &block) end end |