Class: MongoWrapper

Inherits:
Object show all
Includes:
FromHash
Defined in:
lib/mongo_persist/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FromHash

#after_initialize, #from_hash, #initialize

Instance Attribute Details

#objObject

Returns the value of attribute obj.



2
3
4
# File 'lib/mongo_persist/base.rb', line 2

def obj
  @obj
end

Instance Method Details

#get_freshObject



17
18
19
# File 'lib/mongo_persist/base.rb', line 17

def get_fresh
  obj.klass.collection.find_one_object("_id" => obj.mongo_id)
end

#save!Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mongo_persist/base.rb', line 4

def save!
  if obj.mongo_id
    obj.klass.collection.update({'_id' => obj.mongo_id},obj.to_mongo_hash)
  else
    obj.mongo_id = obj.class.collection.save(obj.to_mongo_hash)
  end
  obj
rescue => exp
  require 'pp'
  pp obj.to_mongo_hash
  raise exp
end