Sha256: c2c9569c5b1ed9992bab26155a7e23cf5a7ccf1228e88679b446a126bde2514b

Contents?: true

Size: 508 Bytes

Versions: 41

Compression:

Stored size: 508 Bytes

Contents

# frozen_string_literal: true

module Nanoc::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

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.10.4 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.10.3 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.10.2 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.10.1 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.10.0 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.9 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.8 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.7 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.6 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.5 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.4 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.3 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.2 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.1 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.9.0 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.8.19 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.8.18 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.8.17 lib/nanoc/base/repos/item_rep_repo.rb
nanoc-4.8.16 lib/nanoc/base/repos/item_rep_repo.rb