fast_timestamp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -11
- data/VERSION +1 -1
- data/fast_timestamp.gemspec +1 -1
- data/lib/fast_timestamp.rb +14 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
= fast_timestamp
|
2
2
|
|
3
|
-
|
3
|
+
== Suggested Timestamp model
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
class Timestamp < ActiveRecord::Base
|
6
|
+
index [:timestampable_id, :timestampable_type, :key] # for cache-money only
|
7
|
+
index :id # for cache-money only
|
8
|
+
belongs_to :timestampable, :polymorphic => true
|
9
|
+
validates_presence_of :key, :timestampable_id, :timestampable_type
|
10
|
+
validates_uniqueness_of :key, :scope => [ :timestampable_id, :timestampable_type ]
|
11
|
+
end
|
12
|
+
|
13
|
+
== Suggested Timestamp migration
|
14
|
+
|
15
|
+
create_table "timestamps", :force => true do |t|
|
16
|
+
t.integer "timestampable_id"
|
17
|
+
t.string "timestampable_type"
|
18
|
+
t.string "key"
|
19
|
+
t.datetime "stamped_at"
|
20
|
+
t.datetime "created_at"
|
21
|
+
t.datetime "updated_at"
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index "timestamps", ["timestampable_id", "timestampable_type", "key"], :name => "index_timestamps_on_t_id_and_t_type_and_key"
|
25
|
+
add_index "timestamps", ["timestampable_id", "timestampable_type"], :name => "index_timestamps_on_timestampable_id_and_timestampable_type"
|
15
26
|
|
16
27
|
== Copyright
|
17
28
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/fast_timestamp.gemspec
CHANGED
data/lib/fast_timestamp.rb
CHANGED
@@ -5,14 +5,27 @@ module FastTimestamp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def timestamp!(key)
|
8
|
+
raise "Can't timestamp new records" if new_record?
|
8
9
|
transaction do
|
9
10
|
t = ::Timestamp.find_or_create_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
|
10
11
|
t.update_attribute :stamped_at, Time.zone.now
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
15
|
+
def untimestamp!(key)
|
16
|
+
if t = ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
|
17
|
+
t.destroy
|
18
|
+
end
|
19
|
+
end
|
13
20
|
|
14
21
|
def timestamped?(key)
|
15
|
-
|
22
|
+
raise "Can't check timestamps on new record" if new_record?
|
23
|
+
::Timestamp.exists? :timestampable_type => self.class.base_class.name, :timestampable_id => id, :key => key.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns a Time object
|
27
|
+
def timestamp_for(key)
|
28
|
+
::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s).read_attribute :stamped_at
|
16
29
|
end
|
17
30
|
|
18
31
|
def fast_destroy_timestamps
|