Sha256: 87a755d61a0f86dca1e35d2a4b49c6e4fd5c09c448ecb87b671de4db6ac76ae5

Contents?: true

Size: 1.24 KB

Versions: 41

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Nanoc::Int
  class ActionSequenceBuilder
    include Nanoc::Int::ContractsSupport

    def initialize(item_rep)
      @item_rep = item_rep
      @actions = []
    end

    contract Symbol, Hash => self
    def add_filter(filter_name, params)
      @actions << Nanoc::Int::ProcessingActions::Filter.new(filter_name, params)
      self
    end

    contract String, C::Maybe[Hash] => self
    def add_layout(layout_identifier, params)
      @actions << Nanoc::Int::ProcessingActions::Layout.new(layout_identifier, params)
      self
    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 ? [path] : [])
      self
    end

    contract C::None => Nanoc::Int::ActionSequence
    def action_sequence
      Nanoc::Int::ActionSequence.new(@item_rep, actions: @actions)
    end

    private

    def will_add_snapshot(name)
      @_snapshot_names ||= Set.new
      if @_snapshot_names.include?(name)
        raise Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName.new(@item_rep, name)
      else
        @_snapshot_names << name
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
nanoc-4.8.15 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.14 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.13 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.12 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.11 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.10 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.9 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.8 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.7 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.6 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.5 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.4 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.3 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.2 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.1 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.8.0 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.7.14 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.7.13 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.7.12 lib/nanoc/base/services/action_sequence_builder.rb
nanoc-4.7.11 lib/nanoc/base/services/action_sequence_builder.rb