Class: Listen::Record

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#listenerObject

Returns the value of attribute listener.



5
6
7
# File 'lib/listen/record.rb', line 5

def listener
  @listener
end

#pathsObject

Returns the value of attribute paths.



5
6
7
# File 'lib/listen/record.rb', line 5

def paths
  @paths
end

Instance Method Details

#_init_pathsObject (private)



37
38
39
# File 'lib/listen/record.rb', line 37

def _init_paths
  Hash.new { |h, k| h[k] = Hash.new }
end

#buildObject



28
29
30
31
32
33
# File 'lib/listen/record.rb', line 28

def build
  @paths = _init_paths
  listener.directories.each do |path|
    Actor[:listen_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