Sha256: 7f42104b9b667cf4bb0940572f66804740c67ad17f23ead6691e10ba7d8ee12f

Contents?: true

Size: 597 Bytes

Versions: 2

Compression:

Stored size: 597 Bytes

Contents

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.now
          @changed_attributes.delete 'created_at'
          model.updated_at ||= Time.now
          @changed_attributes.delete 'updated_at'
        }
        before_update lambda {|model|
          model.updated_at = Time.now
          @changed_attributes.delete 'updated_at'
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
davber_couch_potato-0.4.0 lib/couch_potato/persistence/magic_timestamps.rb
couch_potato-0.4.0 lib/couch_potato/persistence/magic_timestamps.rb