Sha256: 06c274a227c85c6c490aa7fc0443cf01c77dda14b00496d8efa8209f015a3d24

Contents?: true

Size: 572 Bytes

Versions: 8

Compression:

Stored size: 572 Bytes

Contents

# frozen_string_literal: true

module Nanoc
  module Int
    # Stores item reps (in memory).
    #
    # @api private
    class ItemRepRepo
      include Enumerable

      def initialize
        @reps = []
        @reps_by_item = {}
      end

      def <<(rep)
        @reps << rep

        @reps_by_item[rep.item] ||= []
        @reps_by_item[rep.item] << rep
      end

      def to_a
        @reps
      end

      def each(&block)
        @reps.each(&block)
        self
      end

      def [](item)
        @reps_by_item.fetch(item, [])
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-4.11.8 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.7 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.6 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.5 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.4 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.3 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.2 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.11.1 lib/nanoc/base/repos/item_rep_repo.rb