Class: Pairtree::Path
- Inherits:
-
Object
- Object
- Pairtree::Path
- Defined in:
- lib/pairtree/path.rb
Constant Summary collapse
- @@leaf_proc =
lambda { |id| id }
Class Method Summary collapse
- .id_to_path(id) ⇒ Object
- .leaf(id) ⇒ Object
- .path_to_id(ppath) ⇒ Object
- .remove!(path) ⇒ Object
- .set_leaf(value = nil, &block) ⇒ Object
Class Method Details
.id_to_path(id) ⇒ Object
23 24 25 26 |
# File 'lib/pairtree/path.rb', line 23 def self.id_to_path id path = File.join(Pairtree::Identifier.encode(id).scan(/..?/), leaf(id)) path.sub(%r{#{File::SEPARATOR}+$}o, "") end |
.leaf(id) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/pairtree/path.rb', line 15 def self.leaf id if @@leaf_proc Pairtree::Identifier.encode(@@leaf_proc.call(id)) else "" end end |
.path_to_id(ppath) ⇒ Object
28 29 30 31 32 |
# File 'lib/pairtree/path.rb', line 28 def self.path_to_id ppath parts = ppath.split(File::SEPARATOR) parts.pop if @@leaf_proc && (parts.last.length > Root::SHORTY_LENGTH) Pairtree::Identifier.decode(parts.join) end |
.remove!(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pairtree/path.rb', line 34 def self.remove! path FileUtils.remove_dir(path, true) parts = path.split(File::SEPARATOR) parts.pop while (parts.length > 0) && (parts.last != "pairtree_root") begin FileUtils.rmdir(parts.join(File::SEPARATOR)) parts.pop rescue SystemCallError break end end end |
.set_leaf(value = nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/pairtree/path.rb', line 5 def self.set_leaf value = nil, &block @@leaf_proc = if value.nil? block elsif value.is_a?(Proc) value else lambda { |id| value } end end |