Sha256: c05ce6883b583cca4f003f65ec2196a1ed94468088cffa672d5d1e12c48a2918

Contents?: true

Size: 673 Bytes

Versions: 23

Compression:

Stored size: 673 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.delete 'created_at'
          model.updated_at ||= (Time.zone || Time).now
          @changed_attributes.delete 'updated_at'
        }
        before_update lambda {|model|
          model.updated_at = (Time.zone || Time).now
          @changed_attributes.delete 'updated_at'
        }
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
couch_potato-1.4.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.3.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.2.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.1.4 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.1.2 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.1.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.1.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.0.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-1.0.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.7.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.7.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.7.0.pre.1 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.6.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.5.7 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-rails2-0.5.7 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-rails2-0.5.6 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.5.6 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.5.5 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.5.4 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.5.3 lib/couch_potato/persistence/magic_timestamps.rb