Module: MongoMapper::Plugins::Touch

Extended by:
ActiveSupport::Concern
Included in:
Document, EmbeddedDocument
Defined in:
lib/mongo_mapper/plugins/touch.rb

Instance Method Summary collapse

Instance Method Details

#touch(key = :updated_at) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/mongo_mapper/plugins/touch.rb', line 6

def touch(key = :updated_at)
  raise ArgumentError, "Invalid key named #{key}" unless self.key_names.include?(key.to_s)
  if self.class.embeddable?
    self.write_attribute(key, Time.now.utc)
    self._parent_document.touch
  else
    self.set(key => Time.now.utc)
  end
  true
end