Class: Listen::Record
- Inherits:
-
Object
- Object
- Listen::Record
- Includes:
- Celluloid
- Defined in:
- lib/listen/record.rb
Instance Attribute Summary collapse
-
#listener ⇒ Object
Returns the value of attribute listener.
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
- #_init_paths ⇒ Object private
- #build ⇒ Object
- #dir_entries(path) ⇒ Object
- #file_data(path) ⇒ Object
-
#initialize(listener) ⇒ Record
constructor
A new instance of Record.
- #set_path(path, data) ⇒ Object
- #unset_path(path) ⇒ Object
Constructor Details
#initialize(listener) ⇒ Record
Returns a new instance of Record.
7 8 9 10 |
# File 'lib/listen/record.rb', line 7 def initialize(listener) @listener = listener @paths = _init_paths end |
Instance Attribute Details
#listener ⇒ Object
Returns the value of attribute listener.
5 6 7 |
# File 'lib/listen/record.rb', line 5 def listener @listener end |
#paths ⇒ Object
Returns the value of attribute paths.
5 6 7 |
# File 'lib/listen/record.rb', line 5 def paths @paths end |
Instance Method Details
#_init_paths ⇒ Object (private)
37 38 39 |
# File 'lib/listen/record.rb', line 37 def _init_paths Hash.new { |h, k| h[k] = Hash.new } end |
#build ⇒ Object
28 29 30 31 32 33 |
# File 'lib/listen/record.rb', line 28 def build @paths = _init_paths listener.directories.each do |path| listener.registry[:change_pool].change(path, type: 'Dir', recursive: true, silence: true) end end |
#dir_entries(path) ⇒ Object
24 25 26 |
# File 'lib/listen/record.rb', line 24 def dir_entries(path) @paths[path.to_s] end |
#file_data(path) ⇒ Object
20 21 22 |
# File 'lib/listen/record.rb', line 20 def file_data(path) @paths[::File.dirname(path)][::File.basename(path)] || {} end |
#set_path(path, data) ⇒ Object
12 13 14 |
# File 'lib/listen/record.rb', line 12 def set_path(path, data) @paths[::File.dirname(path)][::File.basename(path)] = file_data(path).merge(data) end |
#unset_path(path) ⇒ Object
16 17 18 |
# File 'lib/listen/record.rb', line 16 def unset_path(path) @paths[::File.dirname(path)].delete(::File.basename(path)) end |