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
def _clear_cache @_cache = {} end.
- #reload ⇒ Object
- #to_param ⇒ Object
- #update_timestamps ⇒ Object
Instance Method Details
#_cache ⇒ Object
9 10 11 |
# File 'lib/mongo/model/misc.rb', line 9 def _cache @_cache ||= {} end |
#dom_id ⇒ Object
def _clear_cache
@_cache = {}
end
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 |
#reload ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mongo/model/misc.rb', line 27 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 || '').to_s end |
#update_timestamps ⇒ Object
2 3 4 5 6 |
# File 'lib/mongo/model/misc.rb', line 2 def now = Time.now.utc self.created_at ||= now self.updated_at = now end |