Class: Valise::StemDecorator
- Inherits:
-
SearchRoot
- Object
- SearchRoot
- Valise::StemDecorator
- Defined in:
- lib/valise/stem-decorator.rb
Instance Attribute Summary
Attributes inherited from SearchRoot
Instance Method Summary collapse
- #each ⇒ Object
- #full_path(segments) ⇒ Object
- #get_from(item) ⇒ Object
-
#initialize(stem, search_root) ⇒ StemDecorator
constructor
A new instance of StemDecorator.
- #insert(item) ⇒ Object
- #inspect ⇒ Object
- #present?(segments) ⇒ Boolean
- #under_stem(path) ⇒ Object
- #writable?(segments) ⇒ Boolean
- #write(item) ⇒ Object
Methods included from Unpath
Constructor Details
#initialize(stem, search_root) ⇒ StemDecorator
Returns a new instance of StemDecorator.
3 4 5 |
# File 'lib/valise/stem-decorator.rb', line 3 def initialize(stem, search_root) @stem, @search_root = stem, search_root end |
Instance Method Details
#each ⇒ Object
21 22 23 24 25 |
# File 'lib/valise/stem-decorator.rb', line 21 def each @search_root.each do |path| yield(@stem + path) end end |
#full_path(segments) ⇒ Object
27 28 29 30 |
# File 'lib/valise/stem-decorator.rb', line 27 def full_path(segments) segments = under_stem(segments) @search_root.full_path(segments) end |
#get_from(item) ⇒ Object
52 53 54 |
# File 'lib/valise/stem-decorator.rb', line 52 def get_from(item) @search_root.get_from(item) end |
#insert(item) ⇒ Object
48 49 50 |
# File 'lib/valise/stem-decorator.rb', line 48 def insert(item) @search_root.insert(item) end |
#inspect ⇒ Object
17 18 19 |
# File 'lib/valise/stem-decorator.rb', line 17 def inspect "#{self.class.name.split(":").last}:[#{@stem.join("/")}]#{@search_root.inspect}" end |
#present?(segments) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/valise/stem-decorator.rb', line 42 def present?(segments) @search_root.present?(under_stem(segments)) rescue Errors::PathOutsideOfRoot return false end |
#under_stem(path) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/valise/stem-decorator.rb', line 7 def under_stem(path) segments = unpath(path) top_part = segments[0...@stem.length] if top_part == @stem return segments[@stem.length..-1] else raise Errors::PathOutsideOfRoot end end |
#writable?(segments) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/valise/stem-decorator.rb', line 36 def writable?(segments) @search_root.writable?(under_stem(segments)) rescue Errors::PathOutsideOfRoot return false end |
#write(item) ⇒ Object
32 33 34 |
# File 'lib/valise/stem-decorator.rb', line 32 def write(item) @search_root.write(item) end |