Sha256: 579ffeb94193f423b59e66c5fd1927562e77073a835868bb7b5bc6b8d8d3c0b2

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Nanoc::Int
  class RuleMemory
    include Enumerable

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

    def size
      @actions.size
    end

    def [](idx)
      @actions[idx]
    end

    def add_filter(filter_name, params)
      @actions << Nanoc::Int::RuleMemoryActions::Filter.new(filter_name, params)
    end

    def add_layout(layout_identifier, params)
      @actions << Nanoc::Int::RuleMemoryActions::Layout.new(layout_identifier, params)
    end

    def add_snapshot(snapshot_name, final, path)
      will_add_snapshot(snapshot_name)
      @actions << Nanoc::Int::RuleMemoryActions::Snapshot.new(snapshot_name, final, path)
    end

    def snapshot_actions
      @actions.select { |a| a.is_a?(Nanoc::Int::RuleMemoryActions::Snapshot) }
    end

    def serialize
      map(&:serialize)
    end

    def each
      @actions.each { |a| yield(a) }
    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

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-4.1.0a1 lib/nanoc/base/entities/rule_memory.rb