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
20 21 22 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 20 def [](k) build raw[k], k end |
#[]=(k, o) ⇒ Object
28 29 30 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 28 def []=(k,o) raw[k] = o.to_hash end |
#all ⇒ Object
52 53 54 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 52 def all keys.collect { |k| self[k] } end |
#build(hash, k = nil) ⇒ Object
11 12 13 14 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 11 def build(hash, k=nil) return nil if hash.nil? @klass.new(@doc, hash, k) end |
#delete(k) ⇒ Object
24 25 26 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 24 def delete(k) raw.delete(k) end |
#each ⇒ Object
32 33 34 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 32 def each raw.each { |k,v| yield(k, build(v, k)) } end |
#first ⇒ Object
44 45 46 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 44 def first self[keys.first] end |
#keys ⇒ Object
40 41 42 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 40 def keys raw.keys end |
#last ⇒ Object
48 49 50 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 48 def last self[keys.last] end |
#push(obj) ⇒ Object
56 57 58 59 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 56 def push(obj) k = BSON::ObjectId.new.to_s self[k] = obj; k end |
#raw ⇒ Object
16 17 18 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 16 def raw @hash end |
#size ⇒ Object
36 37 38 |
# File 'lib/mongoo/embedded/hash_proxy.rb', line 36 def size raw.size end |