Class: Mongoo::Embedded::ArrayProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoo/embedded/array_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc, array, klass) ⇒ ArrayProxy

Returns a new instance of ArrayProxy.



5
6
7
8
9
# File 'lib/mongoo/embedded/array_proxy.rb', line 5

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

Instance Method Details

#<<(obj) ⇒ Object



61
62
63
# File 'lib/mongoo/embedded/array_proxy.rb', line 61

def <<(obj)
  push(obj.to_hash)
end

#[](i) ⇒ Object



19
20
21
# File 'lib/mongoo/embedded/array_proxy.rb', line 19

def [](i)
  build raw[i], i
end

#[]=(i, o) ⇒ Object



27
28
29
# File 'lib/mongoo/embedded/array_proxy.rb', line 27

def []=(i,o)
  raw[i] = o.to_hash
end

#allObject Also known as: to_a



51
52
53
# File 'lib/mongoo/embedded/array_proxy.rb', line 51

def all
  raw.each_with_index { |v,i| build(v, i) }
end

#build(hash, i = nil) ⇒ Object



11
12
13
# File 'lib/mongoo/embedded/array_proxy.rb', line 11

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

#delete_at(i) ⇒ Object



23
24
25
# File 'lib/mongoo/embedded/array_proxy.rb', line 23

def delete_at(i)
  raw.delete_at(i)
end

#eachObject



31
32
33
# File 'lib/mongoo/embedded/array_proxy.rb', line 31

def each
  raw.each_with_index { |v,i| yield(i, build(v, i)) }
end

#empty?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/mongoo/embedded/array_proxy.rb', line 65

def empty?
  raw.empty?
end

#firstObject



43
44
45
# File 'lib/mongoo/embedded/array_proxy.rb', line 43

def first
  build raw.first, 0
end

#keysObject



39
40
41
# File 'lib/mongoo/embedded/array_proxy.rb', line 39

def keys
  (0..size-1).to_a
end

#lastObject



47
48
49
# File 'lib/mongoo/embedded/array_proxy.rb', line 47

def last
  build raw.last, -1
end

#push(obj) ⇒ Object



57
58
59
# File 'lib/mongoo/embedded/array_proxy.rb', line 57

def push(obj)
  raw << obj.to_hash; raw.index(obj.to_hash)
end

#rawObject



15
16
17
# File 'lib/mongoo/embedded/array_proxy.rb', line 15

def raw
  @array
end

#sizeObject



35
36
37
# File 'lib/mongoo/embedded/array_proxy.rb', line 35

def size
  raw.size
end