Class: Kaisoku::ListenWatcher
- Inherits:
-
Object
- Object
- Kaisoku::ListenWatcher
- Defined in:
- lib/kaisoku/listen_watcher.rb
Constant Summary collapse
- DEFAULT_PATHS =
Watcher::DEFAULT_PATHS
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #each_change ⇒ Object
-
#initialize(configuration: Configuration.new, paths: DEFAULT_PATHS, interval: 0.2) ⇒ ListenWatcher
constructor
A new instance of ListenWatcher.
Constructor Details
#initialize(configuration: Configuration.new, paths: DEFAULT_PATHS, interval: 0.2) ⇒ ListenWatcher
Returns a new instance of ListenWatcher.
10 11 12 13 14 |
# File 'lib/kaisoku/listen_watcher.rb', line 10 def initialize(configuration: Configuration.new, paths: DEFAULT_PATHS, interval: 0.2) @configuration = configuration @paths = Array(paths).empty? ? DEFAULT_PATHS : Array(paths) @interval = interval end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/kaisoku/listen_watcher.rb', line 8 def configuration @configuration end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
8 9 10 |
# File 'lib/kaisoku/listen_watcher.rb', line 8 def paths @paths end |
Instance Method Details
#each_change ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kaisoku/listen_watcher.rb', line 16 def each_change listener = Listen.to(*existing_paths, latency: @interval) do |modified, added, removed| changed = (modified + added + removed).map { |path| configuration.relative_path(path) }.sort yield changed unless changed.empty? end listener.start sleep ensure listener&.stop end |