Class: Bashly::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/bashly/watch.rb

Overview

File system watcher - an ergonomic wrapper around the Watchly gem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*targets, interval: nil) ⇒ Watch

Returns a new instance of Watch.



8
9
10
11
# File 'lib/bashly/watch.rb', line 8

def initialize(*targets, interval: nil)
  @targets = targets.empty? ? ['.'] : targets
  @interval = interval || default_interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



6
7
8
# File 'lib/bashly/watch.rb', line 6

def interval
  @interval
end

#targetsObject (readonly)

Returns the value of attribute targets.



6
7
8
# File 'lib/bashly/watch.rb', line 6

def targets
  @targets
end

Instance Method Details

#on_changeObject



13
14
15
16
17
18
19
20
21
# File 'lib/bashly/watch.rb', line 13

def on_change
  raise ArgumentError, 'block required' unless block_given?

  watcher.on_change do |changes|
    yield normalize(changes)
  end
rescue ::Interrupt => e
  raise Bashly::Interrupt, cause: e
end