Class: Valise::StemDecorator

Inherits:
SearchRoot show all
Defined in:
lib/valise/stem-decorator.rb

Instance Attribute Summary

Attributes inherited from SearchRoot

#segments

Instance Method Summary collapse

Methods included from Unpath

#repath, #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

#eachObject



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

#inspectObject



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

Returns:

  • (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

Returns:

  • (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