Sha256: c15806dffecd6675638af0ffb1c564c11a3c979ad558af2ab9e0769c5b457c0c

Contents?: true

Size: 503 Bytes

Versions: 10

Compression:

Stored size: 503 Bytes

Contents

module Toy
  module Timestamps
    extend ActiveSupport::Concern
    include Attributes
    include Callbacks

    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

10 entries across 10 versions & 1 rubygems

Version Path
toystore-0.13.2 lib/toy/timestamps.rb
toystore-0.13.1 lib/toy/timestamps.rb
toystore-0.13.0 lib/toy/timestamps.rb
toystore-0.12.0 lib/toy/timestamps.rb
toystore-0.11.0 lib/toy/timestamps.rb
toystore-0.10.4 lib/toy/timestamps.rb
toystore-0.10.3 lib/toy/timestamps.rb
toystore-0.10.2 lib/toy/timestamps.rb
toystore-0.10.1 lib/toy/timestamps.rb
toystore-0.10.0 lib/toy/timestamps.rb