class Ahnnotate::VfsDriver::Hash

Public Class Methods

new(files, subdirectories = nil) click to toggle source
# File lib/ahnnotate/vfs_driver/hash.rb, line 4
def initialize(files, subdirectories = nil)
  @files = files
  @subdirectories = nil
end

Public Instance Methods

[](path) click to toggle source
# File lib/ahnnotate/vfs_driver/hash.rb, line 27
def [](path)
  @files[path]
end
[]=(path, content) click to toggle source
# File lib/ahnnotate/vfs_driver/hash.rb, line 31
def []=(path, content)
  if content.nil?
    return
  end

  @files[path] = content
end
dir?(path) click to toggle source
# 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() { |path, content| ... } click to toggle source
# 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) { |path, content| ... } click to toggle source
# 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) click to toggle source
# 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