Class: Valise::StemDecorator

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

Instance Method Summary collapse

Methods inherited from SearchRoot

#to_s

Methods included from Unpath

#collapse, file_from_backtrace, #file_from_backtrace, #from_here, from_here, repath, string_to_segments, unpath, up_to, #up_to

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



36
37
38
39
40
# File 'lib/valise/stem-decorator.rb', line 36

def each
  @search_root.each do |path|
    yield(@stem + path)
  end
end

#full_path(segments) ⇒ Object



42
43
44
45
# File 'lib/valise/stem-decorator.rb', line 42

def full_path(segments)
  segments = under_stem(segments)
  @search_root.full_path(segments)
end

#get_from(item) ⇒ Object



63
64
65
# File 'lib/valise/stem-decorator.rb', line 63

def get_from(item)
  @search_root.get_from(item)
end

#initialize_copy(other) ⇒ Object



9
10
11
12
# File 'lib/valise/stem-decorator.rb', line 9

def initialize_copy(other)
  @stem = other.stem
  @search_root = other.search_root.dup
end

#inspectObject



32
33
34
# File 'lib/valise/stem-decorator.rb', line 32

def inspect
  "#{self.class.name.split(":").last}:[#{@stem.join("/")}]#{@search_root.inspect}"
end

#present?(segments) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/valise/stem-decorator.rb', line 57

def present?(segments)
  @search_root.present?(under_stem(segments))
rescue Errors::PathOutsideOfRoot
  return false
end

#segmentsObject



14
15
16
# File 'lib/valise/stem-decorator.rb', line 14

def segments
  @search_root.segments
end

#segments=(segments) ⇒ Object



18
19
20
# File 'lib/valise/stem-decorator.rb', line 18

def segments=(segments)
  @search_root.segments = segments
end

#under_stem(path) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/valise/stem-decorator.rb', line 22

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)


51
52
53
54
55
# File 'lib/valise/stem-decorator.rb', line 51

def writable?(segments)
  @search_root.writable?(under_stem(segments))
rescue Errors::PathOutsideOfRoot
  return false
end

#write(item) ⇒ Object



47
48
49
# File 'lib/valise/stem-decorator.rb', line 47

def write(item)
  @search_root.write(item)
end