Module: Mongo::Model::Misc
- Defined in:
- lib/mongo/model/misc.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #_cache ⇒ Object
- #dom_id ⇒ Object
- #original ⇒ Object
- #reload ⇒ Object
- #to_param ⇒ Object
- #update_created_at ⇒ Object
- #update_timestamps ⇒ Object
- #update_updated_at ⇒ Object
Instance Method Details
#_cache ⇒ Object
12 13 14 |
# File 'lib/mongo/model/misc.rb', line 12 def _cache @_cache ||= {} end |
#dom_id ⇒ Object
16 17 18 19 |
# File 'lib/mongo/model/misc.rb', line 16 def dom_id # new_record? ? "new_#{self.class.name.underscore}" : to_param to_param end |
#original ⇒ Object
34 35 36 |
# File 'lib/mongo/model/misc.rb', line 34 def original @_original ||= _id? ? self.class.by_id(self._id) : nil end |
#reload ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/mongo/model/misc.rb', line 25 def reload obj = self.class.by_id!(_id || raise("can't reload new document (#{self})!")) instance_variables.each{|n| remove_instance_variable n} obj.instance_variables.each do |n| instance_variable_set n, obj.instance_variable_get(n) end nil end |
#to_param ⇒ Object
21 22 23 |
# File 'lib/mongo/model/misc.rb', line 21 def to_param _id.try :to_s end |
#update_created_at ⇒ Object
2 |
# File 'lib/mongo/model/misc.rb', line 2 def update_created_at; self.created_at = Time.now.utc end |
#update_timestamps ⇒ Object
5 6 7 8 9 |
# File 'lib/mongo/model/misc.rb', line 5 def now = Time.now.utc self.created_at ||= now self.updated_at = now end |
#update_updated_at ⇒ Object
3 |
# File 'lib/mongo/model/misc.rb', line 3 def update_updated_at; self.updated_at = Time.now.utc end |