Class: Mongoo::Core
- Inherits:
-
Object
- Object
- Mongoo::Core
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Validations, Attributes, Embedded::CoreMixin
- Defined in:
- lib/mongoo/core.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #==(val) ⇒ Object
-
#initialize(hash = {}, persisted = false) ⇒ Core
constructor
A new instance of Core.
- #merge!(hash) ⇒ Object
- #mongohash ⇒ Object
- #persisted_mongohash ⇒ Object
- #reset_persisted_mongohash ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(hash = {}, persisted = false) ⇒ Core
Returns a new instance of Core.
13 14 15 16 17 |
# File 'lib/mongoo/core.rb', line 13 def initialize(hash={}, persisted=false) @persisted = persisted init_from_hash(hash) set_persisted_mongohash((persisted? ? mongohash : nil)) end |
Class Method Details
.describe(&block) ⇒ Object
9 10 11 |
# File 'lib/mongoo/core.rb', line 9 def self.describe(&block) Mongoo::DescribeDsl.new(self).describe(&block) end |
Instance Method Details
#==(val) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoo/core.rb', line 19 def ==(val) if val.class.to_s == self.class.to_s if val.persisted? val.id == self.id else self.mongohash.raw_hash == val.mongohash.raw_hash end end end |
#merge!(hash) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/mongoo/core.rb', line 29 def merge!(hash) if hash.is_a?(Mongoo::Mongohash) hash = hash.raw_hash end hash.deep_stringify_keys! hash = mongohash.raw_hash.deep_merge(hash) set_mongohash( Mongoo::Mongohash.new(hash) ) mongohash end |
#mongohash ⇒ Object
57 58 59 |
# File 'lib/mongoo/core.rb', line 57 def mongohash @mongohash end |
#persisted_mongohash ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/mongoo/core.rb', line 68 def persisted_mongohash @persisted_mongohash ||= begin if @serialized_persisted_mongohash Marshal.load(@serialized_persisted_mongohash) end end end |
#reset_persisted_mongohash ⇒ Object
47 48 49 50 |
# File 'lib/mongoo/core.rb', line 47 def reset_persisted_mongohash @persisted = true set_persisted_mongohash(mongohash) end |
#to_hash ⇒ Object
76 77 78 |
# File 'lib/mongoo/core.rb', line 76 def to_hash mongohash.to_hash end |