Module: Mongo::Model::Misc

Defined in:
lib/mongo/model/misc.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_cacheObject



9
10
11
# File 'lib/mongo/model/misc.rb', line 9

def _cache
  @_cache ||= {}
end

#dom_idObject

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

#reloadObject



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_paramObject



21
22
23
# File 'lib/mongo/model/misc.rb', line 21

def to_param
  (_id || '').to_s
end

#update_timestampsObject



2
3
4
5
6
# File 'lib/mongo/model/misc.rb', line 2

def update_timestamps
  now = Time.now.utc
  self.created_at ||= now
  self.updated_at = now
end