lib/nanoc/base/entities/action_sequence.rb in nanoc-4.11.0 vs lib/nanoc/base/entities/action_sequence.rb in nanoc-4.11.1

- old
+ new

@@ -1,84 +1,80 @@ # frozen_string_literal: true -module Nanoc::Int - class ActionSequence - include Nanoc::Int::ContractsSupport - include Enumerable - DDMemoize.activate(self) +module Nanoc + module Int + class ActionSequence + include Nanoc::Core::ContractsSupport + include Enumerable + DDMemoize.activate(self) - attr_reader :item_rep - attr_reader :actions + attr_reader :item_rep + attr_reader :actions - def initialize(item_rep, actions: []) - @item_rep = item_rep - @actions = actions - end + def initialize(item_rep, actions: []) + @item_rep = item_rep + @actions = actions + end - def self.build(rep) - builder = Nanoc::Int::ActionSequenceBuilder.new(rep) - yield(builder) - builder.action_sequence - end + contract C::None => Numeric + def size + @actions.size + end - contract C::None => Numeric - def size - @actions.size - end + contract Numeric => C::Maybe[Nanoc::Core::ProcessingAction] + def [](idx) + @actions[idx] + end - contract Numeric => C::Maybe[Nanoc::Int::ProcessingAction] - def [](idx) - @actions[idx] - end + contract C::None => C::ArrayOf[Nanoc::Core::ProcessingAction] + def snapshot_actions + @actions.select { |a| a.is_a?(Nanoc::Core::ProcessingActions::Snapshot) } + end - contract C::None => C::ArrayOf[Nanoc::Int::ProcessingAction] - def snapshot_actions - @actions.select { |a| a.is_a?(Nanoc::Int::ProcessingActions::Snapshot) } - end + contract C::None => Array + def paths + snapshot_actions.map { |a| [a.snapshot_names, a.paths] } + end - contract C::None => Array - def paths - snapshot_actions.map { |a| [a.snapshot_names, a.paths] } - end + memoized def serialize + serialize_uncached + end - memoized def serialize - serialize_uncached - end + contract C::None => Array + def serialize_uncached + to_a.map(&:serialize) + end - contract C::None => Array - def serialize_uncached - to_a.map(&:serialize) - end + contract C::Func[Nanoc::Core::ProcessingAction => C::Any] => self + def each + @actions.each { |a| yield(a) } + self + end - contract C::Func[Nanoc::Int::ProcessingAction => C::Any] => self - def each - @actions.each { |a| yield(a) } - self - end + contract C::Func[Nanoc::Core::ProcessingAction => C::Any] => self + def map + self.class.new( + @item_rep, + actions: @actions.map { |a| yield(a) }, + ) + end - contract C::Func[Nanoc::Int::ProcessingAction => C::Any] => self - def map - self.class.new( - @item_rep, - actions: @actions.map { |a| yield(a) }, - ) - end + def snapshots_defs + is_binary = @item_rep.item.content.binary? + snapshot_defs = [] - def snapshots_defs - is_binary = @item_rep.item.content.binary? - snapshot_defs = [] - - each do |action| - case action - when Nanoc::Int::ProcessingActions::Snapshot - action.snapshot_names.each do |snapshot_name| - snapshot_defs << Nanoc::Int::SnapshotDef.new(snapshot_name, binary: is_binary) + each do |action| + case action + when Nanoc::Core::ProcessingActions::Snapshot + action.snapshot_names.each do |snapshot_name| + snapshot_defs << Nanoc::Core::SnapshotDef.new(snapshot_name, binary: is_binary) + end + when Nanoc::Core::ProcessingActions::Filter + is_binary = Nanoc::Filter.named!(action.filter_name).to_binary? end - when Nanoc::Int::ProcessingActions::Filter - is_binary = Nanoc::Filter.named!(action.filter_name).to_binary? end - end - snapshot_defs + snapshot_defs + end end end end