class Mongoo::Embedded::ArrayProxy

Public Class Methods

new(doc, array, klass) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 5
def initialize(doc, array, klass)
  @doc   = doc
  @array = array
  @klass = klass
end

Public Instance Methods

<<(obj) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 62
def <<(obj)
  push(obj.to_hash)
end
[](i) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 20
def [](i)
  build raw[i], i
end
[]=(i,o) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 28
def []=(i,o)
  raw[i] = o.to_hash
end
all() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 52
def all
  raw.each_with_index { |v,i| build(v, i) }
end
Also aliased as: to_a
build(hash, i=nil) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 11
def build(hash, i=nil)
  return nil if hash.nil?
  @klass.new(@doc, hash, i)
end
delete_at(i) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 24
def delete_at(i)
  raw.delete_at(i)
end
each() { |i, build(v, i)| ... } click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 32
def each
  raw.each_with_index { |v,i| yield(i, build(v, i)) }
end
empty?() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 66
def empty?
  raw.empty?
end
first() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 44
def first
  build raw.first, 0
end
keys() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 40
def keys
  (0..size-1).to_a
end
last() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 48
def last
  build raw.last, -1
end
push(obj) click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 58
def push(obj)
  raw << obj.to_hash; raw.index(obj.to_hash)
end
raw() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 16
def raw
  @array
end
size() click to toggle source
# File lib/mongoo/embedded/array_proxy.rb, line 36
def size
  raw.size
end
to_a()
Alias for: all