chrono_model 0.12.1 → 0.12.2
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/gemfiles/rails_4.2.gemfile +1 -0
- data/gemfiles/rails_5.0.gemfile +1 -0
- data/gemfiles/rails_5.1.gemfile +1 -0
- data/lib/chrono_model/adapter.rb +1 -1
- data/lib/chrono_model/patches.rb +12 -28
- data/lib/chrono_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69a13f407cf20b6ffbf08382a831c49085158b7d
|
4
|
+
data.tar.gz: 9461316b8a2b3b0498e8d1fc8dc45b15e5492905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ef0ab38b9d33cd457bd33c869128e480d2493120e66fe50624aae94a8a6899df462285ec8003f5f9413f5ccf6d362b53699f20cc5be3b83d9d92ccbdcb65bb
|
7
|
+
data.tar.gz: e3673608283f66ecb82808f9b4ee64e7da9c7c76a44e297e826284755607e38194ebf2a8aad12bbd92bbb5ac7cd91c5d11fb91b72dabd2431671cc22307914b4
|
data/gemfiles/rails_4.2.gemfile
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/lib/chrono_model/adapter.rb
CHANGED
@@ -914,7 +914,7 @@ module ChronoModel
|
|
914
914
|
|
915
915
|
def translate_exception(exception, message)
|
916
916
|
if exception.message =~ /conflicting key value violates exclusion constraint/
|
917
|
-
ActiveRecord::RecordNotUnique.new(message
|
917
|
+
ActiveRecord::RecordNotUnique.new(message)
|
918
918
|
else
|
919
919
|
super
|
920
920
|
end
|
data/lib/chrono_model/patches.rb
CHANGED
@@ -109,9 +109,9 @@ module ChronoModel
|
|
109
109
|
# See +ActiveRecord::Associations::Preloader::NULL_RELATION+
|
110
110
|
NULL_RELATION = ActiveRecord::Associations::Preloader::NULL_RELATION
|
111
111
|
|
112
|
-
#
|
113
|
-
# +preload+.
|
114
|
-
|
112
|
+
# Extend +NULL_RELATION+ by adding the +as_of_time!+ method.
|
113
|
+
# See +preload+ and +AsOfTimeHolder+.
|
114
|
+
NULL_RELATION.class.instance_eval { include AsOfTimeHolder }
|
115
115
|
|
116
116
|
# Patches the AR Preloader (lib/active_record/associations/preloader.rb)
|
117
117
|
# in order to carry around the +as_of_time+ of the original invocation.
|
@@ -119,8 +119,8 @@ module ChronoModel
|
|
119
119
|
# * The +records+ are the parent records where the association is defined
|
120
120
|
# * The +associations+ are the association names involved in preloading
|
121
121
|
# * The +given_preload_scope+ is the preloading scope, that is used only
|
122
|
-
#
|
123
|
-
#
|
122
|
+
# in the :through association and it holds the intermediate records
|
123
|
+
# _through_ which the final associated records are eventually fetched.
|
124
124
|
#
|
125
125
|
# As the +preload_scope+ is passed around to all the different
|
126
126
|
# incarnations of the preloader strategies, we are using it to pass
|
@@ -129,42 +129,26 @@ module ChronoModel
|
|
129
129
|
#
|
130
130
|
# The +preload_scope+ is not nil only for through associations, but the
|
131
131
|
# preloader interfaces expect it to be always defined, for consistency.
|
132
|
+
#
|
132
133
|
# So, AR defines a +NULL_RELATION+ constant to pass around for the
|
133
134
|
# association types that do not have a preload_scope. It quacks like a
|
134
135
|
# Relation, and it contains only the methods that are used by the other
|
135
|
-
# preloader methods. We
|
136
|
-
#
|
136
|
+
# preloader methods. We use this +NULL_RELATION+ to which we have added
|
137
|
+
# the `as_of_time!` holder method.
|
137
138
|
#
|
138
139
|
# For `:through` associations, the +given_preload_scope+ is already a
|
139
140
|
# +Relation+, that already has the +as_of_time+ getters and setters,
|
140
|
-
# so we use
|
141
|
+
# so we use it directly.
|
141
142
|
#
|
142
143
|
def preload(records, associations, given_preload_scope = nil)
|
143
|
-
if (
|
144
|
-
preload_scope =
|
145
|
-
|
146
|
-
else
|
147
|
-
null_relation_preload_scope(as_of_time, given_preload_scope)
|
148
|
-
end
|
144
|
+
if options.key?(:as_of_time)
|
145
|
+
preload_scope = given_preload_scope || NULL_RELATION.dup
|
146
|
+
preload_scope.as_of_time!(options[:as_of_time])
|
149
147
|
end
|
150
148
|
|
151
149
|
super records, associations, preload_scope
|
152
150
|
end
|
153
151
|
|
154
|
-
private
|
155
|
-
def null_relation_preload_scope(as_of_time, given_preload_scope)
|
156
|
-
preload_scope = AS_OF_PRELOAD_SCOPE.new
|
157
|
-
|
158
|
-
preload_scope.as_of_time = as_of_time
|
159
|
-
given_preload_scope ||= NULL_RELATION
|
160
|
-
|
161
|
-
NULL_RELATION.members.each do |member|
|
162
|
-
preload_scope[member] = given_preload_scope[member]
|
163
|
-
end
|
164
|
-
|
165
|
-
return preload_scope
|
166
|
-
end
|
167
|
-
|
168
152
|
module Association
|
169
153
|
# Builds the preloader scope taking into account a potential
|
170
154
|
# +as_of_time+ set above in +Preloader#preload+ and coming from the
|
data/lib/chrono_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrono_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello Barnaba
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|