Sha256: 463960813d6ffcb7d3f4b34bc209d01e39046c34b371532e3efb1baa632e8ec2

Contents?: true

Size: 660 Bytes

Versions: 11

Compression:

Stored size: 660 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
          clear_attribute_changes [:created_at]
          model.updated_at ||= (Time.zone || Time).now
          clear_attribute_changes [:updated_at]
        }
        before_update lambda {|model|
          model.updated_at = (Time.zone || Time).now
          clear_attribute_changes [:updated_at]
        }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
couch_potato-1.17.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.16.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.15.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.14.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.13.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.12.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.12.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.11.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.10.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.10.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.9.0 lib/couch_potato/persistence/magic_timestamps.rb