module CustomTimestamps::Model

Private Instance Methods

_create_record() click to toggle source
Calls superclass method
# File lib/activerecord-custom_timestamps/model.rb, line 16
def _create_record
  if self.record_timestamps
    current_time = current_time_from_proper_timezone

    Array.wrap(self.created_timestamp).each do |column|
      if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
        write_attribute(column.to_s, current_time)
      end
    end

    if self.update_custom_updated_timestamp_on_create
      Array.wrap(self.updated_timestamp).each do |column|
        column = column.to_s
        next if attribute_changed?(column)
        write_attribute(column, current_time)
      end
    end
  end
  
  super
end
_update_record(*args, touch: true, **options) click to toggle source
Calls superclass method
# File lib/activerecord-custom_timestamps/model.rb, line 38
def _update_record(*args, touch: true, **options)
  if touch && should_record_timestamps?
    current_time = current_time_from_proper_timezone

    Array.wrap(self.updated_timestamp).each do |column|
      column = column.to_s
      next if attribute_changed?(column)
      write_attribute(column, current_time)
    end
  end
  super(*args, touch, **options)
end