Class: Bashly::Watch

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

Overview

File system watcher - an ergonomic wrapper around the Listen gem

Constant Summary collapse

DEFAULT_OPTIONS =
{
  force_polling: true,
  latency:       1.0,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*dirs, **options) ⇒ Watch

Returns a new instance of Watch.



13
14
15
16
# File 'lib/bashly/watch.rb', line 13

def initialize(*dirs, **options)
  @options = DEFAULT_OPTIONS.merge(options).freeze
  @dirs = dirs.empty? ? ['.'] : dirs
end

Instance Attribute Details

#dirsObject (readonly)

Returns the value of attribute dirs.



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

def dirs
  @dirs
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#on_changeObject



18
19
20
21
22
23
# File 'lib/bashly/watch.rb', line 18

def on_change(&)
  start(&)
  wait
ensure
  stop
end