Class: Driskell::Listen::Record
- Inherits:
-
Object
- Object
- Driskell::Listen::Record
- Defined in:
- lib/driskell-listen/record/entry.rb,
lib/driskell-listen/record.rb
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #build ⇒ Object
- #dir_entries(rel_path) ⇒ Object
- #file_data(rel_path) ⇒ Object
-
#initialize(directory) ⇒ Record
constructor
A new instance of Record.
- #unset_path(rel_path) ⇒ Object
- #update_dir(rel_path) ⇒ Object
- #update_file(rel_path, data) ⇒ Object
Constructor Details
#initialize(directory) ⇒ Record
Returns a new instance of Record.
8 9 10 11 12 |
# File 'lib/driskell-listen/record.rb', line 8 def initialize(directory) @tree = _auto_hash @tree['.'] = _auto_hash @root = directory.to_s end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/driskell-listen/record.rb', line 6 def root @root end |
Instance Method Details
#build ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/driskell-listen/record.rb', line 42 def build @tree = _auto_hash # TODO: test with a file name given # TODO: test other permissions # TODO: test with mixed encoding remaining = ::Queue.new remaining << Entry.new(root, nil, nil) _fast_build_dir(remaining) until remaining.empty? end |
#dir_entries(rel_path) ⇒ Object
36 37 38 39 40 |
# File 'lib/driskell-listen/record.rb', line 36 def dir_entries(rel_path) rel_path = rel_path.to_s # Do not store anything for the directory when querying tree.has_key?(rel_path) ? tree[rel_path] : {} end |
#file_data(rel_path) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/driskell-listen/record.rb', line 29 def file_data(rel_path) dirname, basename = Pathname(rel_path).split.map(&:to_s) tree[dirname] ||= {} tree[dirname][basename] ||= {} tree[dirname][basename].dup end |
#unset_path(rel_path) ⇒ Object
24 25 26 27 |
# File 'lib/driskell-listen/record.rb', line 24 def unset_path(rel_path) dirname, basename = Pathname(rel_path).split.map(&:to_s) _fast_unset_path(rel_path, dirname, basename) end |
#update_dir(rel_path) ⇒ Object
14 15 16 17 |
# File 'lib/driskell-listen/record.rb', line 14 def update_dir(rel_path) dirname, basename = Pathname(rel_path).split.map(&:to_s) _fast_update_dir(rel_path, dirname, basename) end |
#update_file(rel_path, data) ⇒ Object
19 20 21 22 |
# File 'lib/driskell-listen/record.rb', line 19 def update_file(rel_path, data) dirname, basename = Pathname(rel_path).split.map(&:to_s) _fast_update_file(dirname, basename, data) end |