Class: Valise::SearchRoot
- Inherits:
-
Object
- Object
- Valise::SearchRoot
show all
- Includes:
- Enumerable, Unpath
- Defined in:
- lib/valise/search-root.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
Returns a new instance of SearchRoot.
12
13
14
|
# File 'lib/valise/search-root.rb', line 12
def initialize(path)
@segments = make_pathname(path)
end
|
Instance Attribute Details
#segments ⇒ Object
Returns the value of attribute segments.
16
17
18
|
# File 'lib/valise/search-root.rb', line 16
def segments
@segments
end
|
Instance Method Details
#each(pathmatch = nil) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/valise/search-root.rb', line 18
def each(pathmatch = nil)
paths = [make_pathname("")]
until paths.empty?
rel = paths.shift
path = @segments + rel
if path.directory?
paths += path.children(false).map do |child|
rel + child
end
elsif path.file?
yield rel
end
end
end
|
#full_path(segments) ⇒ Object
42
43
44
|
# File 'lib/valise/search-root.rb', line 42
def full_path(segments)
(@segments + make_pathname(segments)).to_s
end
|
#get_from(item) ⇒ Object
64
65
66
|
# File 'lib/valise/search-root.rb', line 64
def get_from(item)
File::read(item.full_path)
end
|
#inspect ⇒ Object
34
35
36
|
# File 'lib/valise/search-root.rb', line 34
def inspect
"#{self.class.name.split(":").last}:#{[*@segments].join("/")}"
end
|
#present?(segments) ⇒ Boolean
60
61
62
|
# File 'lib/valise/search-root.rb', line 60
def present?(segments)
return File::exists?(full_path(segments))
end
|
#to_s ⇒ Object
38
39
40
|
# File 'lib/valise/search-root.rb', line 38
def to_s
"#{[*@segments].join("/")}"
end
|
#writable?(segments) ⇒ Boolean
55
56
57
58
|
# File 'lib/valise/search-root.rb', line 55
def writable?(segments)
path = full_path(segments)
return (!File::exists?(path) or File::writable?(path))
end
|
#write(item) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/valise/search-root.rb', line 46
def write(item)
return if item.contents.nil?
FileUtils::mkdir_p(::File::dirname(item.full_path))
File::open(item.full_path, "w") do |file|
file.write(item.dump_contents)
end
item
end
|