Class: Listen::Change

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/listen/change.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener) ⇒ Change

Returns a new instance of Change.



10
11
12
# File 'lib/listen/change.rb', line 10

def initialize(listener)
  @listener = listener
end

Instance Attribute Details

#listenerObject

Returns the value of attribute listener.



8
9
10
# File 'lib/listen/change.rb', line 8

def listener
  @listener
end

Instance Method Details

#_log(type, message) ⇒ Object (private)



50
51
52
# File 'lib/listen/change.rb', line 50

def _log(type, message)
  Celluloid.logger.send(type, message)
end

#change(type, path, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/listen/change.rb', line 14

def change(type, path, options = {})
  change = options[:change]
  cookie = options[:cookie]

  if !cookie && listener.silencer.silenced?(path, type)
    _log :debug, "(silenced): #{path.inspect}"
    return
  end

  log_details = options[:silence] && 'recording' || change || 'unknown'
  _log :debug, "#{log_details}: #{type}:#{path} (#{options.inspect})"

  if change
    listener.queue(type, change, path, cookie ? { cookie: cookie } : {})
  else
    return unless (record = listener.sync(:record))
    record.async.still_building! if options[:build]

    if type == :dir
      return unless (change_queue = listener.async(:change_pool))
      Directory.scan(change_queue, record, path, options)
    else
      change = File.change(record, path)
      return if !change || options[:silence]
      listener.queue(:file, change, path)
    end
  end
rescue Celluloid::Task::TerminatedError
  _log :debug, "Change#change was terminated: #{$!.inspect}"
rescue RuntimeError
  _log :error, "Change#change crashed #{$!.inspect}:#{$@.join("\n")}"
  raise
end