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
62 63 64 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 62 def <<(obj) push(obj.to_hash) end |
#[](i) ⇒ Object
20 21 22 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 20 def [](i) build raw[i], i end |
#[]=(i, o) ⇒ Object
28 29 30 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 28 def []=(i,o) raw[i] = o.to_hash end |
#all ⇒ Object Also known as: to_a
52 53 54 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 52 def all raw.each_with_index { |v,i| build(v, i) } end |
#build(hash, i = nil) ⇒ Object
11 12 13 14 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 24 def delete_at(i) raw.delete_at(i) end |
#each ⇒ Object
32 33 34 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 32 def each raw.each_with_index { |v,i| yield(i, build(v, i)) } end |
#empty? ⇒ Boolean
66 67 68 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 66 def empty? raw.empty? end |
#first ⇒ Object
44 45 46 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 44 def first build raw.first, 0 end |
#keys ⇒ Object
40 41 42 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 40 def keys (0..size-1).to_a end |
#last ⇒ Object
48 49 50 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 48 def last build raw.last, -1 end |
#push(obj) ⇒ Object
58 59 60 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 58 def push(obj) raw << obj.to_hash; raw.index(obj.to_hash) end |
#raw ⇒ Object
16 17 18 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 16 def raw @array end |
#size ⇒ Object
36 37 38 |
# File 'lib/mongoo/embedded/array_proxy.rb', line 36 def size raw.size end |