seamusabshere-has_timestamps 1.5.4 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/has_timestamps.rb +1 -1
- data/lib/timestamp.rb +18 -20
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/has_timestamps.rb
CHANGED
@@ -30,7 +30,7 @@ module HasTimestamps
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
has_many :timestamps, opts.merge(:class_name => '
|
33
|
+
has_many :timestamps, opts.merge(:class_name => '::Timestamp', :as => :timestampable) do
|
34
34
|
def [](key)
|
35
35
|
t = fetch_timestamp(key, false)
|
36
36
|
t.stamped_at unless t.nil?
|
data/lib/timestamp.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
1
|
+
class Timestamp < ActiveRecord::Base
|
2
|
+
class << self
|
3
|
+
def create_table
|
4
|
+
self.connection.create_table(:timestamps) do |t|
|
5
|
+
t.integer :timestampable_id
|
6
|
+
t.string :timestampable_type
|
7
|
+
t.string :key
|
8
|
+
t.datetime :stamped_at
|
9
|
+
t.timestamps
|
12
10
|
end
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
def drop_table
|
14
|
+
self.connection.drop_table(:timestamps)
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
belongs_to :timestampable, :polymorphic => true
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
validates_presence_of :key, :timestampable_id, :timestampable_type
|
21
|
+
validates_uniqueness_of :key, :scope => [ :timestampable_id, :timestampable_type ]
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
def to_param
|
24
|
+
self.key
|
27
25
|
end
|
28
26
|
end
|