Sha256: 2c659ebc0ac169a51d562096051ed4d31821497dd757ee85b9b72406a5e0cae5

Contents?: true

Size: 524 Bytes

Versions: 5

Compression:

Stored size: 524 Bytes

Contents

# frozen_string_literal: true

module CouchbaseOrm
  module Timestamps
    # This module handles the behavior for setting up document updated at
    # timestamp.
    module Updated
      extend ActiveSupport::Concern

      included do
        set_callback :save, :before, -> {
          return if frozen?
          return unless changed? || new_record?

          time = Time.current
          self.updated_at = time if !updated_at_changed?
        }, if: -> { attributes.has_key? 'updated_at' }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
couchbase-orm-2.0.4 lib/couchbase-orm/timestamps/updated.rb
couchbase-orm-2.0.3 lib/couchbase-orm/timestamps/updated.rb
couchbase-orm-2.0.2 lib/couchbase-orm/timestamps/updated.rb
couchbase-orm-2.0.1 lib/couchbase-orm/timestamps/updated.rb
couchbase-orm-2.0.0 lib/couchbase-orm/timestamps/updated.rb