lib/dagger/vertex.rb in ruby-dagger-0.2.0 vs lib/dagger/vertex.rb in ruby-dagger-0.2.1

- old
+ new

@@ -37,41 +37,47 @@ end alias to_s name def [](key) key = key.to_key_path - @inherited[key.drop(1)] if key.prefix?('^') + return @inherited[key.drop(1)] if key.prefix?('^') + @forest[key] end def fetch(key, *default, &block) key = key.to_key_path - @inherited.fetch(key.drop(1), *default, &block) if key.prefix?('^') + return @inherited.fetch(key.drop(1), *default, &block) if key.prefix?('^') + @forest.fetch(key, *default, &block) end def <<(keytree) @local << keytree end def edge_added(edge) return unless edge.head?(self) + @inherited << edge.tail.to_key_wood end def edge_removed(edge) return unless edge.head?(self) + @inherited.reject! { |tree| tree.equal?(edge.tail.to_key_wood) } end def added_to_graph(graph) raise %(belongs another graph) if @graph&.!= graph + @graph = graph end def removed_from_graph(graph) raise %(not part of graph) if @graph&.!= graph + @graph = nil end def flatten(cleanup: true) forest = initialize_forest(true) @@ -80,10 +86,11 @@ forest[key.drop(1)] end flattened = forest.flatten return flattened unless cleanup + flattened.to_h.delete_if { |key| key.to_s.start_with?('_') } flattened end def to_h @@ -92,11 +99,11 @@ def to_yaml flatten(cleanup: true).to_yaml end - def to_json - flatten(cleanup: true).to_json + def to_json(*args) + flatten(cleanup: true).to_json(*args) end private def initialize_forest(cached)