lib/dagger/graph.rb in ruby-dagger-0.1.1 vs lib/dagger/graph.rb in ruby-dagger-0.2.0
- old
+ new
@@ -1,23 +1,24 @@
+# frozen_string_literal: true
+
require 'tangle'
require 'tangle/mixin/directory'
require_relative 'vertex'
module Dagger
# Specialization of Tangle::DAG
class Graph < Tangle::DAG
- DEFAULT_MIXINS = [Tangle::Mixin::Directory].freeze
-
- def self.load(dir)
+ 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)
+ new(directory: dir_options, currify: true)
end
- def initialize(*)
+ def initialize(mixins: [Tangle::Mixin::Directory], **)
@deferred_edges = []
super
@deferred_edges.each do |args|
tail, head, *kwargs = args
add_edge(*[tail, head].map { |name| fetch(name) }, *kwargs)
@@ -26,10 +27,14 @@
def select(&_filter)
vertices.select { |vertex| yield(self, vertex) }
end
+ def cached?
+ !(!@cached)
+ end
+
protected
def symlink_loader(path:, parent:, lstat:, **)
return unless lstat.symlink?
@@ -40,10 +45,10 @@
def directory_loader(path:, parent:, lstat:, **)
return unless lstat.directory?
path = local_path(path)
- vertex = Vertex.new(path)
+ vertex = Vertex.new(path, cached: cached?)
add_vertex(vertex)
return true if parent.nil?
parent = local_path(parent)
defer_edge(parent, path)
end