Class: Ahnnotate::Vfs
- Inherits:
-
Object
- Object
- Ahnnotate::Vfs
- Includes:
- Enumerable
- Defined in:
- lib/ahnnotate/vfs.rb
Instance Method Summary collapse
- #[](path) ⇒ Object
- #[]=(path, content) ⇒ Object
- #each ⇒ Object
- #each_in(paths, extensions = []) ⇒ Object
-
#initialize(driver) ⇒ Vfs
constructor
A new instance of Vfs.
Constructor Details
#initialize(driver) ⇒ Vfs
Returns a new instance of Vfs.
5 6 7 |
# File 'lib/ahnnotate/vfs.rb', line 5 def initialize(driver) @driver = driver end |
Instance Method Details
#[](path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ahnnotate/vfs.rb', line 25 def [](path) if @driver.dir?(path) raise Error::VfsReadError, "can't read a directory" end if !accessible_path?(path) raise Error::VfsOutsideOfRoot, "path seems to be outside of root" end @driver[path] end |
#[]=(path, content) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ahnnotate/vfs.rb', line 9 def []=(path, content) if content.nil? return end if @driver.dir?(path) raise Error::VfsWriteError, "can't write to directory" end if !accessible_path?(path) raise Error::VfsOutsideOfRoot, "path seems to be outside of root" end @driver[path] = content end |
#each ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ahnnotate/vfs.rb', line 37 def each if !block_given? return enum_for(:each) end @driver.each(&Proc.new) end |
#each_in(paths, extensions = []) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ahnnotate/vfs.rb', line 45 def each_in(paths, extensions = []) if !block_given? return enum_for(:each_in, paths) end paths = if paths.is_a?(Array) paths else [paths] end extensions = [extensions].flatten.compact @driver.each_in(paths) do |path, content| if extensions.any? if !extensions.include?(File.extname(path)) next end end yield(path, content) end end |