Sha256: a84a522ccbcfd3476ce733d5f02790d564c457b12932e3195fe08e15d42b6b13

Contents?: true

Size: 684 Bytes

Versions: 5

Compression:

Stored size: 684 Bytes

Contents

require 'active_support/time'

module CouchPotato
  module MagicTimestamps #:nodoc:
    def self.included(base)
      base.instance_eval do
        property :created_at, :type => Time
        property :updated_at, :type => Time

        before_create lambda {|model|
          model.created_at ||= (Time.zone || Time).now
          @changed_attributes.try :delete, 'created_at'
          model.updated_at ||= (Time.zone || Time).now
          @changed_attributes.try :delete, 'updated_at'
        }
        before_update lambda {|model|
          model.updated_at = (Time.zone || Time).now
          @changed_attributes.try :delete, 'updated_at'
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
couch_potato-1.7.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.7.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.6.5 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.6.4 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.6.3 lib/couch_potato/persistence/magic_timestamps.rb