class Ahnnotate::VfsDriver::Filesystem

Public Class Methods

new(root:) click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 6
def initialize(root:)
  @root = root
end

Public Instance Methods

[](path) click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 36
def [](path)
  path = root.join(path)

  if path.exist?
    File.read(path)
  end
end
[]=(path, content) click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 44
def []=(path, content)
  path = root.join(path)
  holding_directory = path.dirname

  if holding_directory.file?
    raise "File is not a directory"
  end

  if !holding_directory.exist?
    holding_directory.mkpath
  end

  File.write(path, content)
end
dir?(path) click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 59
def dir?(path)
  root.join(path).directory?
end
each() { |relpath, read| ... } click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 10
def each
  paths =
    root
      .glob("**/*")
      .select(&:file?)
      .map { |path| path.relative_path_from(root).to_s }

  root.glob("**/*").select(&:file?).each do |abspath|
    relpath = abspath.relative_path_from(root).to_s

    yield relpath, File.read(abspath)
  end
end
each_in(subset_paths) { |relpath, read| ... } click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 24
def each_in(subset_paths)
  subset_paths = subset_paths.map { |path| root.join(path) }

  subset_paths.each do |subset_path|
    subset_path.glob("**/*").select(&:file?).map do |abspath|
      relpath = abspath.relative_path_from(root).to_s

      yield relpath, File.read(abspath)
    end
  end
end

Private Instance Methods

root() click to toggle source
# File lib/ahnnotate/vfs_driver/filesystem.rb, line 65
def root
  Pathname.new(@root)
end