timestamped_column 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,29 @@
|
|
1
|
-
module TimestampedColumn
|
2
|
-
|
1
|
+
module TimestampedColumn
|
2
|
+
module ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
included do
|
6
|
+
before_save :update_timestamped_column_times
|
7
|
+
cattr_accessor :timestamped_columns
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
module ClassMethods
|
11
|
+
def timestamped_column(column, opts={})
|
12
|
+
timestamp_column = opts[:column] || "#{column}_updated_at"
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
self.timestamped_columns ||= {}
|
15
|
+
self.timestamped_columns[column] = timestamp_column
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
module InstanceMethods
|
20
|
+
private
|
21
|
+
def update_timestamped_column_times
|
22
|
+
if self.timestamped_columns && changes.any?
|
23
|
+
self.timestamped_columns.each do |column, timestamp_column|
|
24
|
+
if changes[column.to_s]
|
25
|
+
send "#{timestamp_column}=", Time.zone.now
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timestamped_column
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-23 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70338618301700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70338618301700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70338618301280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70338618301280
|
36
36
|
description: Records modified time for individual columns.
|
37
37
|
email:
|
38
38
|
- james@jamesbrooks.net
|