Class: Mongoo::Embedded::ArrayProxy
- Inherits:
-
Object
- Object
- Mongoo::Embedded::ArrayProxy
- Defined in:
- lib/mongoo/embedded/array_proxy.rb
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #[](i) ⇒ Object
- #[]=(i, o) ⇒ Object
- #all ⇒ Object (also: #to_a)
- #build(hash, i = nil) ⇒ Object
- #delete_at(i) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(doc, array, klass) ⇒ ArrayProxy
constructor
A new instance of ArrayProxy.
- #keys ⇒ Object
- #last ⇒ Object
- #push(obj) ⇒ Object
- #raw ⇒ Object
- #size ⇒ Object
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 |
#all ⇒ Object 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 |
#each ⇒ Object
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
65 66 67 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 65 def empty? raw.empty? end |
#first ⇒ Object
43 44 45 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 43 def first build raw.first, 0 end |
#keys ⇒ Object
39 40 41 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 39 def keys (0..size-1).to_a end |
#last ⇒ Object
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 |
#raw ⇒ Object
15 16 17 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 15 def raw @array end |
#size ⇒ Object
35 36 37 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 35 def size raw.size end |