hoardable 0.12.4 → 0.12.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.
- checksums.yaml +4 -4
- data/lib/hoardable/error.rb +12 -0
- data/lib/hoardable/has_one.rb +19 -3
- data/lib/hoardable/version.rb +1 -1
- 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: 931223031ac56883e27e5f11da07eae3b59793ca8a2c77ce4e20f67cdb730174
|
4
|
+
data.tar.gz: 452472091834577883a5d56ea8b1af4375120648eaff066119edc2459c2cf035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414a407c30d2aa0f504cd89773a83dd0b775bbbed51c8f7dbaa4225141aa34d301aac6167b6ce3553af02f03e8e2d1a053b58b4f9946814d5fb1b17282f86817
|
7
|
+
data.tar.gz: 995256175f51743332171ec32e232bdf01abb7288df8987d75b4e164499cf99610dc8605a9956fed3eb0edbb736b46ae24906fdf00cf5c14fa9ec99d752647d2
|
data/lib/hoardable/error.rb
CHANGED
@@ -15,4 +15,16 @@ module Hoardable
|
|
15
15
|
)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
# An error to be raised when 'updated_at' columns are missing for {Hoardable::Model}s.
|
20
|
+
class UpdatedAtColumnMissingError < Error
|
21
|
+
def initialize(source_table_name)
|
22
|
+
super(
|
23
|
+
<<~LOG
|
24
|
+
'#{source_table_name}' does not have an 'updated_at' column, so Hoardable cannot look up
|
25
|
+
associated record versions with it. Add an 'updated_at' column to '#{source_table_name}'.
|
26
|
+
LOG
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
18
30
|
end
|
data/lib/hoardable/has_one.rb
CHANGED
@@ -15,14 +15,30 @@ module Hoardable
|
|
15
15
|
|
16
16
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
17
17
|
def #{name}
|
18
|
-
|
18
|
+
reflection = _reflections['#{name}']
|
19
|
+
return super if reflection.klass.name.match?(/^ActionText/)
|
19
20
|
|
20
|
-
super&.
|
21
|
-
|
21
|
+
super&.at(hoardable_at_timestamp) ||
|
22
|
+
reflection.klass.at(hoardable_at_timestamp).find_by(
|
23
|
+
{
|
24
|
+
reflection.type => self.class.name.sub(/Version$/, ''),
|
25
|
+
reflection.foreign_key => hoardable_id
|
26
|
+
}.reject { |key, _| key.blank? }
|
27
|
+
)
|
22
28
|
end
|
23
29
|
RUBY
|
24
30
|
end
|
25
31
|
end
|
32
|
+
|
33
|
+
included do
|
34
|
+
private
|
35
|
+
|
36
|
+
def hoardable_at_timestamp
|
37
|
+
Hoardable.instance_variable_get('@at') || updated_at
|
38
|
+
rescue NameError
|
39
|
+
raise(UpdatedAtColumnMissingError, self.class.table_name)
|
40
|
+
end
|
41
|
+
end
|
26
42
|
end
|
27
43
|
private_constant :HasOne
|
28
44
|
end
|
data/lib/hoardable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoardable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- justin talbott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|