Sha256: 5bf81f478ec055aeb5b3fe3083776dbb8cdb9634983d261ac3a9ee1981abbed0

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

require 'forwardable'

module ActiveMocker
module Mock

  class Collection

    include Enumerable

    def initialize(collection=[])
      @collection = [*collection]
    end

    def <<(*records)
      collection.concat(records.flatten)
    end

    extend ::Forwardable
    def_delegators :@collection, :take, :push, :clear, :first, :last, :concat, :replace, :distinct, :uniq, :count, :size, :length, :empty?, :any?, :include?, :delete
    alias distinct uniq

    def select(&block)
      collection.select(&block)
    end

    def each(&block)
      collection.each do |item|
        block.call(item)
      end
    end

    def map(&block)
      collection.map do |item|
        block.call(item)
      end
    end

    def to_a
      @collection
    end

    def to_ary
      to_a
    end

    def hash
      @collection.hash
    end

    def ==(val)
      @collection == val
    end

    protected

    attr_accessor :collection

  end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_mocker-1.5.2 lib/active_mocker/mock/collection.rb