Class: Listen::Record
- Inherits:
-
Object
- Object
- Listen::Record
- Includes:
- Celluloid
- Defined in:
- lib/listen/record.rb
Instance Attribute Summary collapse
-
#listener ⇒ Object
TODO: deprecate.
-
#paths ⇒ Object
TODO: deprecate.
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(type, path, data = {}) ⇒ Object
- #still_building! ⇒ Object
- #unset_path(path) ⇒ Object
Constructor Details
#initialize(listener) ⇒ Record
Returns a new instance of Record.
8 9 10 11 |
# File 'lib/listen/record.rb', line 8 def initialize(listener) @listener = listener @paths = _init_paths end |
Instance Attribute Details
#listener ⇒ Object
TODO: deprecate
6 7 8 |
# File 'lib/listen/record.rb', line 6 def listener @listener end |
#paths ⇒ Object
TODO: deprecate
6 7 8 |
# File 'lib/listen/record.rb', line 6 def paths @paths end |
Instance Method Details
#_init_paths ⇒ Object (private)
49 50 51 |
# File 'lib/listen/record.rb', line 49 def _init_paths Hash.new { |h, k| h[k] = Hash.new } end |
#build ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/listen/record.rb', line 30 def build @last_build_at = Time.now @paths = _init_paths listener.directories.each do |path| = { recursive: true, silence: true, build: true } listener.sync(:change_pool).change(:dir, path, ) end sleep 0.01 until @last_build_at + 0.1 < Time.now rescue Celluloid.logger.warn "build crashed: #{$!.inspect}" raise end |
#dir_entries(path) ⇒ Object
26 27 28 |
# File 'lib/listen/record.rb', line 26 def dir_entries(path) @paths[path.to_s].dup end |
#file_data(path) ⇒ Object
22 23 24 |
# File 'lib/listen/record.rb', line 22 def file_data(path) @paths[::File.dirname(path)][::File.basename(path)] || {} end |
#set_path(type, path, data = {}) ⇒ Object
13 14 15 16 |
# File 'lib/listen/record.rb', line 13 def set_path(type, path, data = {}) new_data = file_data(path).merge(data).merge(type: type) @paths[::File.dirname(path)][::File.basename(path)] = new_data end |
#still_building! ⇒ Object
43 44 45 |
# File 'lib/listen/record.rb', line 43 def still_building! @last_build_at = Time.now end |
#unset_path(path) ⇒ Object
18 19 20 |
# File 'lib/listen/record.rb', line 18 def unset_path(path) @paths[::File.dirname(path)].delete(::File.basename(path)) end |