Class: VirtualFS::Local
Instance Method Summary
collapse
Methods inherited from Backend
#cache, #dotfolders_for, #map_entries
Constructor Details
#initialize(opts = {}) ⇒ Local
Returns a new instance of Local.
8
9
10
11
12
|
# File 'lib/virtualfs/local.rb', line 8
def initialize(opts={})
super opts
@path = ::File.realpath(opts.fetch(:path))
end
|
Instance Method Details
#entries(path = '/') ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/virtualfs/local.rb', line 14
def entries(path='/')
p = VirtualFS.realpath(path)
contents = ::Dir.entries(::File.join(@path, p)).map { |entry| ::File.join(p, entry) }
cache do
map_entries(contents) { |path| ::File.directory?(::File.join(@path, path)) }
end
end
|
#glob(pattern, path = '/') ⇒ Object
Also known as:
[]
24
25
26
27
28
29
30
31
32
|
# File 'lib/virtualfs/local.rb', line 24
def glob(pattern, path='/')
p = VirtualFS.realpath(path)
contents = ::Dir.glob(::File.join(@path, p, pattern)).map { |entry| entry.sub(@path, '') }
cache do
map_entries(contents) { |path| ::File.directory?(::File.join(@path, path)) }
end
end
|
#stream_for(path) ⇒ Object
34
35
36
37
38
|
# File 'lib/virtualfs/local.rb', line 34
def stream_for(path)
path = VirtualFS.realpath(path)
StringIO.new( ::File.open(::File.join(@path, path), 'r') { |io| io.read } )
end
|