Class: Lookbook::FileWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/file_watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pollingObject (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

#listenersObject (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

#startObject



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

#stopObject



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