Sha256: 75a58b531f85564cccf3d43a65642444be36aaf5014cc4d74cb4f66c867deb7b
Contents?: true
Size: 843 Bytes
Versions: 14
Compression:
Stored size: 843 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| # The object may not set created_at. # @see https://github.com/opennorth/pupa-ruby/issues/17 object.created_at = object.document['created_at'] if object.document object.updated_at = Time.now.utc end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems