hoardable 0.12.4 → 0.12.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hoardable/database_client.rb +14 -0
- data/lib/hoardable/error.rb +12 -0
- data/lib/hoardable/has_one.rb +6 -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: 6f7aee7a5af21b6cb079385ea2e49eb243b420c797eb8044f14af18f14abdd23
|
4
|
+
data.tar.gz: c92fc3a0adc3c253856f393c6478514e6f1fe83237b75a37b89dd01325e94773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24c3d1f3a985c0169a9c5d89335ef322fb86d45b8492e81197c089bf30f7431d94340d2b9d1805f42fd381bf52fcc4991ceb7fb66429ee87c5cf7025fc29c99
|
7
|
+
data.tar.gz: 171dc6db5742a1bde4f78aa9c9990325cf9658884e147888d938e02f79e0d739dd145d266c8ede202d0ee859e8a4daa323b9c8c9d12af173d002f5535577dadb
|
@@ -40,6 +40,20 @@ module Hoardable
|
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
|
+
def has_one_find_conditions(reflection)
|
44
|
+
{
|
45
|
+
reflection.type => source_record.class.name.sub(/Version$/, ''),
|
46
|
+
reflection.foreign_key => source_record.hoardable_id,
|
47
|
+
'name' => (reflection.name.to_s.sub(/^rich_text_/, '') if reflection.class_name.match?(/RichText$/))
|
48
|
+
}.reject { |k, v| k.nil? || v.nil? }
|
49
|
+
end
|
50
|
+
|
51
|
+
def has_one_at_timestamp
|
52
|
+
Hoardable.instance_variable_get('@at') || source_record.updated_at
|
53
|
+
rescue NameError
|
54
|
+
raise(UpdatedAtColumnMissingError, source_record.class.table_name)
|
55
|
+
end
|
56
|
+
|
43
57
|
def source_attributes_without_primary_key
|
44
58
|
source_record.attributes_before_type_cast.without(source_primary_key)
|
45
59
|
end
|
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,10 +15,13 @@ 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_client.has_one_at_timestamp) ||
|
22
|
+
reflection.klass.at(hoardable_client.has_one_at_timestamp).find_by(
|
23
|
+
hoardable_client.has_one_find_conditions(reflection)
|
24
|
+
)
|
22
25
|
end
|
23
26
|
RUBY
|
24
27
|
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.6
|
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
|