class Mongoo::Core

Public Class Methods

describe(&block) click to toggle source
# File lib/mongoo/core.rb, line 9
def self.describe(&block)
  Mongoo::DescribeDsl.new(self).describe(&block)
end
new(hash={}, persisted=false) click to toggle source
# 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

Public Instance Methods

==(val) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/mongoo/core.rb, line 57
def mongohash
  @mongohash
end
persisted_mongohash() click to toggle source
# 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() click to toggle source
# File lib/mongoo/core.rb, line 47
def reset_persisted_mongohash
  @persisted = true
  set_persisted_mongohash(mongohash)
end
to_hash() click to toggle source
# File lib/mongoo/core.rb, line 76
def to_hash
  mongohash.to_hash
end

Protected Instance Methods

init_from_hash(hash) click to toggle source
# File lib/mongoo/core.rb, line 39
def init_from_hash(hash)
  unless hash.is_a?(Mongoo::Mongohash)
    hash = Mongoo::Mongohash.new(hash)
  end
  set_mongohash hash
end
set_mongohash(mongohash) click to toggle source
# File lib/mongoo/core.rb, line 52
def set_mongohash(mongohash)
  @mongohash = mongohash
end
set_persisted_mongohash(hash) click to toggle source
# File lib/mongoo/core.rb, line 61
def set_persisted_mongohash(hash)
  @serialized_persisted_mongohash = Marshal.dump(hash)
  @persisted_mongohash = nil
  true
end