Sha256: 0d2352ccab2a0682c95a930c31daee8016a137fc65f6022b58be866f29496c88
Contents?: true
Size: 836 Bytes
Versions: 1
Compression:
Stored size: 836 Bytes
Contents
module TimestampedColumn::ActiveRecord extend ActiveSupport::Concern included do before_save :update_timestamped_column_times cattr_accessor :timestamped_columns end module ClassMethods def timestamped_column(column, opts={}) timestamp_column = opts[:column] || "#{column}_updated_at" self.timestamped_columns ||= {} self.timestamped_columns[column] = timestamp_column end end module InstanceMethods private def update_timestamped_column_times if self.timestamped_columns && changes.any? self.timestamped_columns.each do |column, timestamp_column| if changes[column.to_s] send "#{timestamp_column}=", Time.zone.now end end end end end end class ActiveRecord::Base include TimestampedColumn::ActiveRecord end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timestamped_column-0.1.0 | lib/timestamped_column/active_record.rb |