Sha256: cf80ab06ea0c426349bc1241d2796fa9c46209472820f78c01a7d16b017c10bb

Contents?: true

Size: 683 Bytes

Versions: 3

Compression:

Stored size: 683 Bytes

Contents

require 'active_support/time_with_zone'

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

3 entries across 3 versions & 1 rubygems

Version Path
couch_potato-rails2-0.5.10 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-rails2-0.5.9 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-rails2-0.5.8 lib/couch_potato/persistence/magic_timestamps.rb