lib/nanoc/base/repos/dependency_store.rb in nanoc-4.7.6 vs lib/nanoc/base/repos/dependency_store.rb in nanoc-4.7.7

- old
+ new

@@ -1,20 +1,21 @@ module Nanoc::Int # @api private class DependencyStore < ::Nanoc::Int::Store include Nanoc::Int::ContractsSupport - # @return [Array<Nanoc::Int::Item, Nanoc::Int::Layout>] - attr_accessor :objects + attr_accessor :items + attr_accessor :layouts - # @param [Array<Nanoc::Int::Item, Nanoc::Int::Layout>] objects - def initialize(objects, site: nil) + def initialize(items, layouts, site: nil) super(Nanoc::Int::Store.tmp_path_for(site: site, store_name: 'dependencies'), 4) - @objects = objects + @items = items + @layouts = layouts + @new_objects = [] - @graph = Nanoc::Int::DirectedGraph.new([nil] + @objects) + @graph = Nanoc::Int::DirectedGraph.new([nil] + @items.to_a + @layouts.to_a) end contract C::Or[Nanoc::Int::Item, Nanoc::Int::ItemRep, Nanoc::Int::Layout] => C::ArrayOf[Nanoc::Int::Dependency] def dependencies_causing_outdatedness_of(object) objects_causing_outdatedness_of(object).map do |other_object| @@ -111,16 +112,29 @@ vertices: @graph.vertices.map { |obj| obj && obj.reference }, } end def data=(new_data) + objects = @items.to_a + @layouts.to_a + # Create new graph - @graph = Nanoc::Int::DirectedGraph.new([nil] + @objects) + @graph = Nanoc::Int::DirectedGraph.new([nil] + objects) # Load vertices previous_objects = new_data[:vertices].map do |reference| - @objects.find { |obj| reference == obj.reference } + if reference + case reference[0] + when :item + @items.object_with_identifier(reference[1]) + when :layout + @layouts.object_with_identifier(reference[1]) + else + raise Nanoc::Int::Errors::InternalInconsistency, "unrecognised reference #{reference[0].inspect}" + end + else + nil + end end # Load edges new_data[:edges].each do |edge| from_index, to_index, props = *edge @@ -128,9 +142,9 @@ to = to_index && previous_objects[to_index] @graph.add_edge(from, to, props: props) end # Record dependency from all items on new items - @new_objects = @objects - previous_objects + @new_objects = objects - previous_objects end end end