lib/nanoc/base/entities/rule_memory.rb in nanoc-4.4.5 vs lib/nanoc/base/entities/rule_memory.rb in nanoc-4.4.6
- old
+ new
@@ -1,13 +1,13 @@
module Nanoc::Int
class RuleMemory
include Nanoc::Int::ContractsSupport
include Enumerable
- def initialize(item_rep)
+ def initialize(item_rep, actions: [])
@item_rep = item_rep
- @actions = []
+ @actions = actions
end
contract C::None => Numeric
def size
@actions.size
@@ -28,14 +28,14 @@
def add_layout(layout_identifier, params)
@actions << Nanoc::Int::ProcessingActions::Layout.new(layout_identifier, params)
self
end
- contract Symbol, C::Bool, C::Maybe[String] => self
- def add_snapshot(snapshot_name, final, path)
- will_add_snapshot(snapshot_name) if final
- @actions << Nanoc::Int::ProcessingActions::Snapshot.new(snapshot_name, final, path)
+ 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)
self
end
contract C::None => C::ArrayOf[Nanoc::Int::ProcessingAction]
def snapshot_actions
@@ -54,16 +54,24 @@
end
end
# TODO: Add contract
def serialize
- map(&:serialize)
+ to_a.map(&:serialize)
end
contract C::Func[Nanoc::Int::ProcessingAction => C::Any] => self
def each
@actions.each { |a| yield(a) }
self
+ end
+
+ contract C::Func[Nanoc::Int::ProcessingAction => C::Any] => self
+ def map
+ self.class.new(
+ @item_rep,
+ actions: @actions.map { |a| yield(a) },
+ )
end
private
def will_add_snapshot(name)