Sha256: f8df78875ce7b4915d0a12b01900467430bb5ad57b2e6c131103226e2b6eeea3

Contents?: true

Size: 457 Bytes

Versions: 14

Compression:

Stored size: 457 Bytes

Contents

module Toy
  module Timestamps
    extend ActiveSupport::Concern

    module ClassMethods
      def timestamps
        attribute(:created_at, Time)
        attribute(:updated_at, Time)

        before_create do |record|
          now = Time.now
          record.created_at = now unless created_at?
          record.updated_at = now
        end

        before_update do |record|
          record.updated_at = Time.now
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
toystore-0.9.0 lib/toy/timestamps.rb
toystore-0.8.3 lib/toy/timestamps.rb
toystore-0.8.2 lib/toy/timestamps.rb
toystore-0.8.1 lib/toy/timestamps.rb
toystore-0.8.0 lib/toy/timestamps.rb
toystore-0.7.0 lib/toy/timestamps.rb
toystore-0.6.6 lib/toy/timestamps.rb
toystore-0.6.5 lib/toy/timestamps.rb
toystore-0.6.4 lib/toy/timestamps.rb
toystore-0.6.3 lib/toy/timestamps.rb
toystore-0.6.2 lib/toy/timestamps.rb
toystore-0.6.1 lib/toy/timestamps.rb
toystore-0.6 lib/toy/timestamps.rb
toystore-0.5 lib/toy/timestamps.rb