self_updated_at 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/self_updated_at/version.rb +1 -1
- data/lib/self_updated_at.rb +16 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b54580e68038973e417f3252349922e850c464ae4ea9b6c368e1f79c66abf797
|
4
|
+
data.tar.gz: 72ecbed4343b3b2fc6f8c1cb9af8d8b8e99763513b8ff0ef3444b9dc944983d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855148380e9af5f2339ce5469dcc33a1b4102f655db192065b4fb6245a793e9e58894c4f276acd55a551ace28be1269a32502aa37d2889f266faa86698a1007f
|
7
|
+
data.tar.gz: a8cff45786caa14ce5f0bb7ae83461fd46faf6ca469731caf08ac655dea77a291953d85aa2672042ee15c661278f12a69fb81c5fb71132b1f25ccf57d3a441e8
|
data/Gemfile.lock
CHANGED
data/lib/self_updated_at.rb
CHANGED
@@ -27,12 +27,24 @@ module SelfUpdatedAt
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module ClassMethods
|
30
|
-
def self_updated_at(update_column_name, columns:)
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def self_updated_at(update_column_name, columns: [], methods: [])
|
31
|
+
before_create do
|
32
|
+
current_time = self.class.default_timezone == :utc ? Time.now.utc : Time.now
|
33
|
+
write_attribute(update_column_name, current_time) if eval("#{update_column_name}.nil?")
|
34
|
+
self
|
35
|
+
end
|
36
|
+
before_update do
|
37
|
+
current_time = self.class.default_timezone == :utc ? Time.now.utc : Time.now
|
38
|
+
# for ActiveRecord ~> 5.1
|
39
|
+
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new('5.1')
|
40
|
+
columns_changed = columns.any? { |c| will_save_change_to_attribute?(c) }
|
41
|
+
else
|
42
|
+
columns_changed = columns.any? { |c| attribute_changed?(c) }
|
43
|
+
end
|
44
|
+
if (columns_changed || methods.any? { |m| send(m) })
|
34
45
|
write_attribute(update_column_name, current_time)
|
35
46
|
end
|
47
|
+
self
|
36
48
|
end
|
37
49
|
end
|
38
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: self_updated_at
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nishio Takuya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|