Sha256: 00ea7f1231a4d9ef5b4ca521dfd5db9ecf04aff5d00a81eec59f1c81ee9aded7

Contents?: true

Size: 837 Bytes

Versions: 5

Compression:

Stored size: 837 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class Collection < Proxy
        include Enumerable

        def to_a
          load_target

          target.is_a?(Array) ?
            target :
            Array(target)
        end

        alias_method :to_ary, :to_a

        def each(&block)
          to_a.each(&block)
        end

        def [](val)
          objs = to_a
          objs ? objs[val] : nil
        end

        def empty?
          to_a.empty?
        end

        def size
          to_a.size
        end

        def length
          to_a.length
        end

        def reset
          super
          target = []
        end

        def read
          self
        end

        def write(value)
          replace(value)
          read
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 lib/mongo_mapper/plugins/associations/proxy/collection.rb
mongo_mapper-0.16.0 lib/mongo_mapper/plugins/associations/proxy/collection.rb
mongo_mapper-0.15.6 lib/mongo_mapper/plugins/associations/proxy/collection.rb
mongo_mapper-0.15.5 lib/mongo_mapper/plugins/associations/proxy/collection.rb
mongo_mapper-0.15.4 lib/mongo_mapper/plugins/associations/proxy/collection.rb