chrono_model 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bf80e2ead7e4bd268485039492504007f1bef1d
4
- data.tar.gz: ec80e086d0723533e8f7bb06e78ec58e1a9edd39
3
+ metadata.gz: 69a13f407cf20b6ffbf08382a831c49085158b7d
4
+ data.tar.gz: 9461316b8a2b3b0498e8d1fc8dc45b15e5492905
5
5
  SHA512:
6
- metadata.gz: eea3f10b7f18fd38718716ef4c90fc3a65ac4e789a6ae6a888080d655a1b2fae6761830242cf03bb911e9e7f090706c66ddf71bab20b76fb2f76ff3a68caf25e
7
- data.tar.gz: fa5936bc34ca7820eefceb3064af13c12d5e323f0f8bede5e01062936b5ae7003bbe104b162a61469e95825a2b74b1580e05a21e5591dd537185842bb75d50d8
6
+ metadata.gz: 81ef0ab38b9d33cd457bd33c869128e480d2493120e66fe50624aae94a8a6899df462285ec8003f5f9413f5ccf6d362b53699f20cc5be3b83d9d92ccbdcb65bb
7
+ data.tar.gz: e3673608283f66ecb82808f9b4ee64e7da9c7c76a44e297e826284755607e38194ebf2a8aad12bbd92bbb5ac7cd91c5d11fb91b72dabd2431671cc22307914b4
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "activerecord", "~> 4.2.0"
4
4
  gem "rails", "~> 4.2.0"
5
+ gem "pg", "~> 0.18"
5
6
 
6
7
  gemspec :path => "../"
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "activerecord", "~> 5.0.0"
4
4
  gem "rails", "~> 5.0.0"
5
+ gem "pg", "~> 0.18"
5
6
 
6
7
  gemspec :path => "../"
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "activerecord", "~> 5.1.0"
4
4
  gem "rails", "~> 5.1.0"
5
+ gem "pg", "~> 0.18"
5
6
 
6
7
  gemspec :path => "../"
@@ -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, exception)
917
+ ActiveRecord::RecordNotUnique.new(message)
918
918
  else
919
919
  super
920
920
  end
@@ -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
- # Extension of +NULL_RELATION+ adding an +as_of_time+ property. See
113
- # +preload+.
114
- AS_OF_PRELOAD_SCOPE = Struct.new(:as_of_time, *NULL_RELATION.members)
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
- # in the :through association and it holds the intermediate records
123
- # _through_ which the final associated records are eventually fetched.
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 extend AR's +NULL_RELATION+ with an `as_of_time`
136
- # property.
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 them here.
141
+ # so we use it directly.
141
142
  #
142
143
  def preload(records, associations, given_preload_scope = nil)
143
- if (as_of_time = options[:as_of_time])
144
- preload_scope = if given_preload_scope.respond_to?(:as_of_time!)
145
- given_preload_scope.as_of_time!(as_of_time)
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
@@ -1,3 +1,3 @@
1
1
  module ChronoModel
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.2"
3
3
  end
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.1
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: 2017-11-20 00:00:00.000000000 Z
12
+ date: 2018-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord