Class: Olelo::VirtualFS::Embedded
- Inherits:
-
Olelo::VirtualFS
- Object
- Olelo::VirtualFS
- Olelo::VirtualFS::Embedded
- Defined in:
- lib/olelo/virtualfs.rb
Instance Method Summary collapse
- #glob(*names) ⇒ Object
-
#initialize(file) ⇒ Embedded
constructor
A new instance of Embedded.
- #mtime(name) ⇒ Object
- #read(name) ⇒ Object
Methods inherited from Olelo::VirtualFS
Constructor Details
#initialize(file) ⇒ Embedded
Returns a new instance of Embedded.
59 60 61 62 |
# File 'lib/olelo/virtualfs.rb', line 59 def initialize(file) @file = file @cache = {} end |
Instance Method Details
#glob(*names) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/olelo/virtualfs.rb', line 86 def glob(*names) code, data = File.read(@file).split('__END__', 2) data.to_s.each_line do |line| if line =~ /^@@\ss*([^\s]+)\s*/ && names.any? {|pattern| File.fnmatch(pattern, $1) } yield(self, $1) end end end |
#mtime(name) ⇒ Object
96 97 98 |
# File 'lib/olelo/virtualfs.rb', line 96 def mtime(name) File.mtime(@file) end |
#read(name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/olelo/virtualfs.rb', line 65 def read(name) @cache[name] ||= begin code, data = File.read(@file).split('__END__', 2) content = nil data.to_s.each_line do |line| if line =~ /^@@\s*([^\s]+)\s*/ if name == $1 content = '' elsif content break end elsif content content << line end end content || raise(IOError, "#{name} not found") end end |