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
11 12 13 |
# File 'lib/mongo/model/misc.rb', line 11 def _cache @_cache ||= {} end |
#dom_id ⇒ Object
15 16 17 18 |
# File 'lib/mongo/model/misc.rb', line 15 def dom_id # new_record? ? "new_#{self.class.name.underscore}" : to_param to_param end |
#original ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/mongo/model/misc.rb', line 33 def original unless _cache[:original_cached] _cache[:original_cached] = true _cache[:original] = id && self.class.by_id(id) end _cache[:original] end |
#reload ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/mongo/model/misc.rb', line 24 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
20 21 22 |
# File 'lib/mongo/model/misc.rb', line 20 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 |