Module: Recliner::Timestamps

Extended by:
ActiveSupport::Concern
Defined in:
lib/recliner/timestamps.rb

Overview

Recliner automatically timestamps create and update operations if the document has properties named created_at/created_on or updated_at/updated_on.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_with_timestampsObject



36
37
38
39
40
41
# File 'lib/recliner/timestamps.rb', line 36

def create_with_timestamps
  write_attribute(:created_at, Time.now) if properties.include?(:created_at)
  write_attribute(:created_on, Time.now) if properties.include?(:created_on)
  
  create_without_timestamps
end

#save_with_timestamps(*args) ⇒ Object



22
23
24
25
26
27
# File 'lib/recliner/timestamps.rb', line 22

def save_with_timestamps(*args)
  write_attribute(:updated_at, Time.now) if properties.include?(:updated_at)
  write_attribute(:updated_on, Time.now) if properties.include?(:updated_on)
  
  save_without_timestamps(*args)
end

#save_with_timestamps!(*args) ⇒ Object



29
30
31
32
33
34
# File 'lib/recliner/timestamps.rb', line 29

def save_with_timestamps!(*args)
  write_attribute(:updated_at, Time.now) if properties.include?(:updated_at)
  write_attribute(:updated_on, Time.now) if properties.include?(:updated_on)
  
  save_without_timestamps!(*args)
end