Class: Valise::StemDecorator
Instance Method Summary
collapse
Methods inherited from SearchRoot
#to_s
Methods included from Unpath
#clean_pathname, #containing_workspace, #current_directory, #file_from_backtrace, #from_here, #make_pathname, #starting_directory, #up_to, #up_until
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
39
40
41
42
43
|
# File 'lib/valise/stem-decorator.rb', line 39
def each
@search_root.each do |path|
yield(@stem + path)
end
end
|
#full_path(segments) ⇒ Object
45
46
47
48
|
# File 'lib/valise/stem-decorator.rb', line 45
def full_path(segments)
segments = under_stem(segments)
@search_root.full_path(segments)
end
|
#get_from(item) ⇒ Object
66
67
68
|
# File 'lib/valise/stem-decorator.rb', line 66
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
|
#inspect ⇒ Object
35
36
37
|
# File 'lib/valise/stem-decorator.rb', line 35
def inspect
"#{self.class.name.split(":").last}:[#{@stem.to_s}]#{@search_root.inspect}"
end
|
#present?(segments) ⇒ Boolean
60
61
62
63
64
|
# File 'lib/valise/stem-decorator.rb', line 60
def present?(segments)
@search_root.present?(under_stem(segments))
rescue Errors::PathOutsideOfRoot
return false
end
|
#segments ⇒ Object
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
|
#stem_pattern ⇒ Object
22
23
24
|
# File 'lib/valise/stem-decorator.rb', line 22
def stem_pattern
(@stem + "**").to_s
end
|
#under_stem(path) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/valise/stem-decorator.rb', line 26
def under_stem(path)
segments = make_pathname(path)
if path.fnmatch?(stem_pattern, File::FNM_DOTMATCH)
return path.relative_path_from(@stem)
else
raise Errors::PathOutsideOfRoot
end
end
|
#writable?(segments) ⇒ Boolean
54
55
56
57
58
|
# File 'lib/valise/stem-decorator.rb', line 54
def writable?(segments)
@search_root.writable?(under_stem(segments))
rescue Errors::PathOutsideOfRoot
return false
end
|
#write(item) ⇒ Object
50
51
52
|
# File 'lib/valise/stem-decorator.rb', line 50
def write(item)
@search_root.write(item)
end
|