Class: VirtualFS::Local
Instance Method Summary collapse
- #entries(path = '/') ⇒ Object
- #glob(pattern, path = '/') ⇒ Object (also: #[])
-
#initialize(opts = {}) ⇒ Local
constructor
A new instance of Local.
- #stream_for(path) ⇒ Object
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 |