Skip to content

Commit

Permalink
[dm-timestamps] Further simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Kubb committed Nov 23, 2008
1 parent 6a2365d commit 1072cff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dm-timestamps/lib/dm-timestamps.rb
Expand Up @@ -8,10 +8,10 @@ module Timestamp
Resource.append_inclusions self

TIMESTAMP_PROPERTIES = {
:updated_at => [ DateTime, lambda { |r| r.updated_at = DateTime.now } ],
:updated_on => [ Date, lambda { |r| r.updated_on = Date.today } ],
:created_at => [ DateTime, lambda { |r| r.created_at ||= DateTime.now if r.new_record? } ],
:created_on => [ Date, lambda { |r| r.created_on ||= Date.today if r.new_record? } ],
:updated_at => [ DateTime, lambda { |r| DateTime.now } ],
:updated_on => [ Date, lambda { |r| Date.today } ],
:created_at => [ DateTime, lambda { |r| r.created_at || (DateTime.now if r.new_record?) } ],
:created_on => [ Date, lambda { |r| r.created_on || (Date.today if r.new_record?) } ],
}.freeze

def self.included(model)
Expand All @@ -26,7 +26,7 @@ def set_timestamps
return unless dirty?
TIMESTAMP_PROPERTIES.each do |name,(_type,proc)|
if property = model.properties[name]
proc.call(self) unless attribute_dirty?(name)
property.set(self, proc.call(self)) unless attribute_dirty?(name)
end
end
end
Expand Down

0 comments on commit 1072cff

Please sign in to comment.