Sha256: 933a13297e239856f115133a3874e3df7bad8c8d77c32dca1dcf0a5b1e8f9747

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

module Mongoo
  module Embedded
    class ArrayProxy

      def initialize(doc, array, klass)
        @doc   = doc
        @array = array
        @klass = klass
      end

      def build(hash)
        @klass.new(@doc,hash)
      end

      def raw
        @array
      end

      def [](index)
        if res = raw[index]
          build(res)
        end
      end

      def range(min=0, max=-1)
        if res = raw[min..max]
          res.collect { |h| build(h) }
        end
      end

      def all
        range
      end

      def each
        raw.each { |h| yield(build(h)) }
      end

      def push(o)
        raw << o.to_hash
      end

      def pop(o)
        raw.pop o.to_hash
      end

      def size
        raw.size
      end

    end # ArrayProxy
  end # Embedded
end # Mongoo

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoo-0.4.8 lib/mongoo/embedded/array_proxy.rb
mongoo-0.4.7 lib/mongoo/embedded/array_proxy.rb