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

#_dir_change(path, options) ⇒ Object (private)



39
40
41
# File 'lib/listen/change.rb', line 39

def _dir_change(path, options)
  Directory.new(listener, path, options).scan
end

#_file_change(path, options) ⇒ Object (private)



32
33
34
35
36
37
# File 'lib/listen/change.rb', line 32

def _file_change(path, options)
  change = File.new(listener, path).change
  if change && listener.listen? && !options[:silence]
    _notify_listener(change, path)
  end
end

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



43
44
45
# File 'lib/listen/change.rb', line 43

def _notify_listener(change, path, options = {})
  listener.changes << { change => path }.merge(options)
end

#_silencerObject (private)



47
48
49
# File 'lib/listen/change.rb', line 47

def _silencer
  listener.registry[:silencer]
end

#change(path, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/listen/change.rb', line 14

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

  unless cookie
    #TODO: remove silencing here (it's done later)
    return if _silencer.silenced?(path, options[:type])
  end

  if change
    _notify_listener(change, path, cookie ? { cookie: cookie } : {})
  else
    send("_#{options[:type].downcase}_change", path, options)
  end
end