Class: Listen::Record
- Inherits:
-
Object
show all
- Includes:
- Celluloid
- Defined in:
- lib/listen/record/entry.rb,
lib/listen/record.rb,
lib/listen/record/symlink_detector.rb
Defined Under Namespace
Classes: Entry, SymlinkDetector
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(listener) ⇒ Record
Returns a new instance of Record.
12
13
14
15
|
# File 'lib/listen/record.rb', line 12
def initialize(listener)
@listener = listener
@paths = _auto_hash
end
|
Instance Attribute Details
#listener ⇒ Object
10
11
12
|
# File 'lib/listen/record.rb', line 10
def listener
@listener
end
|
#paths ⇒ Object
10
11
12
|
# File 'lib/listen/record.rb', line 10
def paths
@paths
end
|
Instance Method Details
#add_dir(dir, rel_path) ⇒ Object
17
18
19
20
|
# File 'lib/listen/record.rb', line 17
def add_dir(dir, rel_path)
return if [nil, '', '.'].include? rel_path
@paths[dir.to_s][rel_path] ||= {}
end
|
#build ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/listen/record.rb', line 61
def build
start = Time.now.to_f
@paths = _auto_hash
listener.directories.each do |directory|
_fast_build(directory.to_s)
end
Celluloid::Logger.info "Record.build(): #{Time.now.to_f - start} seconds"
rescue
Celluloid::Logger.warn "build crashed: #{$ERROR_INFO.inspect}"
raise
end
|
#dir_entries(dir, rel_path) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/listen/record.rb', line 45
def dir_entries(dir, rel_path)
tree = if [nil, '', '.'].include? rel_path.to_s
@paths[dir.to_s]
else
@paths[dir.to_s][rel_path.to_s] ||= _auto_hash
@paths[dir.to_s][rel_path.to_s]
end
result = {}
tree.each do |key, values|
result[key] = values.key?(:mtime) ? values : {}
end
result
end
|
#file_data(dir, rel_path) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/listen/record.rb', line 32
def file_data(dir, rel_path)
root = @paths[dir.to_s]
dirname, basename = Pathname(rel_path).split.map(&:to_s)
if [nil, '', '.'].include? dirname
root[basename] ||= {}
root[basename].dup
else
root[dirname] ||= {}
root[dirname][basename] ||= {}
root[dirname][basename].dup
end
end
|
#unset_path(dir, rel_path) ⇒ Object
27
28
29
30
|
# File 'lib/listen/record.rb', line 27
def unset_path(dir, rel_path)
dirname, basename = Pathname(rel_path).split.map(&:to_s)
_fast_unset_path(dir, dirname, basename)
end
|
#update_file(dir, rel_path, data) ⇒ Object
22
23
24
25
|
# File 'lib/listen/record.rb', line 22
def update_file(dir, rel_path, data)
dirname, basename = Pathname(rel_path).split.map(&:to_s)
_fast_update_file(dir, dirname, basename, data)
end
|