Class: Mongoo::Embedded::HashProxy
- Inherits:
-
Object
- Object
- Mongoo::Embedded::HashProxy
- Defined in:
- lib/mongoo/embedded/hash_proxy.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, o) ⇒ Object
- #all ⇒ Object
- #build(hash, k = nil) ⇒ Object
- #delete(k) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(doc, hash, klass) ⇒ HashProxy
constructor
A new instance of HashProxy.
- #keys ⇒ Object
- #last ⇒ Object
- #push(obj) ⇒ Object
- #raw ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(doc, hash, klass) ⇒ HashProxy
Returns a new instance of HashProxy.
5 6 7 8 9 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 5 def initialize(doc, hash, klass) @doc = doc @hash = hash @klass = klass end |
Instance Method Details
#[](k) ⇒ Object
19 20 21 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 19 def [](k) build raw[k], k end |
#[]=(k, o) ⇒ Object
27 28 29 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 27 def []=(k,o) raw[k] = o.to_hash end |
#all ⇒ Object
51 52 53 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 51 def all keys.collect { |k| self[k] } end |
#build(hash, k = nil) ⇒ Object
11 12 13 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 11 def build(hash, k=nil) @klass.new(@doc, hash, k) end |
#delete(k) ⇒ Object
23 24 25 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 23 def delete(k) raw.delete(k) end |
#each ⇒ Object
31 32 33 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 31 def each raw.each { |k,v| yield(k, build(v, k)) } end |
#first ⇒ Object
43 44 45 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 43 def first self[keys.first] end |
#keys ⇒ Object
39 40 41 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 39 def keys raw.keys end |
#last ⇒ Object
47 48 49 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 47 def last self[keys.last] end |
#push(obj) ⇒ Object
55 56 57 58 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 55 def push(obj) k = BSON::ObjectId.new.to_s self[k] = obj; k end |
#raw ⇒ Object
15 16 17 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 15 def raw @hash end |
#size ⇒ Object
35 36 37 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 35 def size raw.size end |