Sha256: d156227a3f4736de4a41a3f06a940c8246fc8e55326f2fb8ba5fb91ebc3dc60c

Contents?: true

Size: 651 Bytes

Versions: 2

Compression:

Stored size: 651 Bytes

Contents

module Pupa
  module Concerns
    # Adds the Popolo `created_at` and `updated_at` properties to a model. The
    # `created_at` and `updated_at` properties will automatically be set when
    # the object is inserted into or updated in the database.
    module Timestamps
      extend ActiveSupport::Concern

      included do
        attr_accessor :created_at, :updated_at
        dump :created_at, :updated_at

        set_callback(:create, :before) do |object|
          object.created_at = Time.now.utc
        end

        set_callback(:save, :before) do |object|
          object.updated_at = Time.now.utc
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pupa-0.0.10 lib/pupa/models/concerns/timestamps.rb
pupa-0.0.9 lib/pupa/models/concerns/timestamps.rb