lib/nanoc/base/entities/rule_memory.rb in nanoc-4.6.1 vs lib/nanoc/base/entities/rule_memory.rb in nanoc-4.6.2
- old
+ new
@@ -31,11 +31,11 @@
end
contract Symbol, C::Maybe[String] => self
def add_snapshot(snapshot_name, path)
will_add_snapshot(snapshot_name)
- @actions << Nanoc::Int::ProcessingActions::Snapshot.new(snapshot_name, path)
+ @actions << Nanoc::Int::ProcessingActions::Snapshot.new([snapshot_name], path ? [path] : [])
self
end
contract C::None => C::ArrayOf[Nanoc::Int::ProcessingAction]
def snapshot_actions
@@ -45,15 +45,13 @@
contract C::None => C::Bool
def any_layouts?
@actions.any? { |a| a.is_a?(Nanoc::Int::ProcessingActions::Layout) }
end
- contract C::None => Hash
+ contract C::None => Array
def paths
- snapshot_actions.each_with_object({}) do |action, paths|
- paths[action.snapshot_name] = action.path
- end
+ snapshot_actions.map { |a| [a.snapshot_names, a.paths] }
end
# TODO: Add contract
def serialize
to_a.map(&:serialize)
@@ -69,9 +67,21 @@
def map
self.class.new(
@item_rep,
actions: @actions.map { |a| yield(a) },
)
+ end
+
+ def compact_snapshots
+ actions = []
+ @actions.each do |action|
+ if [actions.last, action].all? { |a| a.is_a?(Nanoc::Int::ProcessingActions::Snapshot) }
+ actions[-1] = actions.last.update(snapshot_names: action.snapshot_names, paths: action.paths)
+ else
+ actions << action
+ end
+ end
+ self.class.new(@item_rep, actions: actions)
end
private
def will_add_snapshot(name)