class Dagger::Graph

Specialization of Tangle::DAG

Public Class Methods

load(dir, cached: false) click to toggle source
# File lib/dagger/graph.rb, line 10
def self.load(dir, cached: false)
  @cached = cached
  dir_options = {
    root: File.realpath(dir),
    loaders: %i[symlink_loader directory_loader keytree_loader]
  }
  new(directory: dir_options, currify: true)
end
new(mixins: [Tangle::Mixin::Directory], **) click to toggle source
Calls superclass method
# File lib/dagger/graph.rb, line 19
def initialize(mixins: [Tangle::Mixin::Directory], **)
  @deferred_edges = []
  super
  @deferred_edges.each do |args|
    *args, kwargs = args
    add_edge(*args.map { |name| fetch(name) }, **kwargs)
  end
end

Public Instance Methods

cached?() click to toggle source
# File lib/dagger/graph.rb, line 32
def cached?
  !(!@cached)
end
select() { |self, vertex| ... } click to toggle source
# File lib/dagger/graph.rb, line 28
def select(&_filter)
  vertices.select { |vertex| yield(self, vertex) }
end

Protected Instance Methods

directory_loader(path:, parent:, lstat:, **) click to toggle source
# File lib/dagger/graph.rb, line 46
def directory_loader(path:, parent:, lstat:, **)
  return unless lstat.directory?

  path = local_path(path)
  vertex = Vertex.new(path, cached: cached?)
  add_vertex(vertex)
  return true if parent.nil?

  parent = local_path(parent)
  defer_edge(parent, path)
end
keytree_loader(path:, parent:, lstat:, **) click to toggle source
# File lib/dagger/graph.rb, line 58
def keytree_loader(path:, parent:, lstat:, **)
  return unless lstat.file?

  fetch(local_path(parent)) << KeyTree.open(path)
end

Private Instance Methods

defer_edge(*args, **kwargs) click to toggle source
# File lib/dagger/graph.rb, line 75
def defer_edge(*args, **kwargs)
  @deferred_edges << [*args, kwargs]
end
local_path(path) click to toggle source
# File lib/dagger/graph.rb, line 66
def local_path(path)
  raise "#{path} outside root" unless path.start_with?(root_directory)

  result = path.delete_prefix(root_directory)
  return '/' if result.empty?

  result
end