lib/fast_timestamp.rb in fast_timestamp-0.0.3 vs lib/fast_timestamp.rb in fast_timestamp-0.0.4
- old
+ new
@@ -3,15 +3,11 @@
def self.included(base)
base.class_eval { after_destroy :fast_destroy_timestamps }
end
def timestamp!(key)
- raise "Can't timestamp new records" if new_record?
- transaction do
- t = ::Timestamp.find_or_create_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
- t.update_attribute :stamped_at, Time.zone.now
- end
+ set_timestamp! key, Time.zone.now
end
def untimestamp!(key)
if t = ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
t.destroy
@@ -25,9 +21,17 @@
# returns a Time object
def timestamp_for(key)
if t = ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
t.read_attribute :stamped_at
+ end
+ end
+
+ def set_timestamp!(key, time)
+ raise "Can't timestamp new records" if new_record?
+ transaction do
+ t = ::Timestamp.find_or_create_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
+ t.update_attribute :stamped_at, time
end
end
def fast_destroy_timestamps
::Timestamp.destroy_all :timestampable_type => self.class.base_class.name, :timestampable_id => id