Class: Ahnnotate::VfsDriver::Hash
- Inherits:
-
Object
- Object
- Ahnnotate::VfsDriver::Hash
- Defined in:
- lib/ahnnotate/vfs_driver/hash.rb
Instance Method Summary collapse
- #[](path) ⇒ Object
- #[]=(path, content) ⇒ Object
- #dir?(path) ⇒ Boolean
- #each ⇒ Object
- #each_in(subset_paths) ⇒ Object
-
#initialize(files, subdirectories = nil) ⇒ Hash
constructor
A new instance of Hash.
- #subset(in: nil) ⇒ Object
Constructor Details
#initialize(files, subdirectories = nil) ⇒ Hash
Returns a new instance of Hash.
4 5 6 7 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 4 def initialize(files, subdirectories = nil) @files = files @subdirectories = nil end |
Instance Method Details
#[](path) ⇒ Object
27 28 29 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 27 def [](path) @files[path] end |
#[]=(path, content) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 31 def []=(path, content) if content.nil? return end @files[path] = content end |
#dir?(path) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 45 def dir?(path) path_with_trailing_slash = if path[-1] == "/" path else path + "/" end @files.any? do |filepath, _| filepath.start_with?(path_with_trailing_slash) end end |
#each ⇒ Object
9 10 11 12 13 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 9 def each @files.each do |path, content| yield path, content end end |
#each_in(subset_paths) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 15 def each_in(subset_paths) subset_patterns = subset_paths.map { |path| /\A#{path}\b/ } @files.each do |path, content| if subset_patterns.none? { |pattern| pattern === path } next end yield path, content end end |
#subset(in: nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/ahnnotate/vfs_driver/hash.rb', line 39 def subset(in: nil) subdirectories = binding.local_variable_get(:in) self.class.new(the_subset, subdirectories) end |