activerecord-virtual_attributes 1.2.0 → 1.3.0

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
  SHA256:
3
- metadata.gz: 9a6c500c61ceb22d7703070013800f894b62a5efd8bf14e3e5aec0e24afdb5e1
4
- data.tar.gz: 1e8c99b6823e09e10e39958c3f50651e5f1b558a76ef15377f23cd13571fd2cc
3
+ metadata.gz: 5fe283d7922a8073591f5c00728e976c3c7ed2ec9dbe51972224b35f55095498
4
+ data.tar.gz: ec6c34d345f4ecf01a48d53f266f13b0b91b2a8e87d72c5b5cffffcda6101c36
5
5
  SHA512:
6
- metadata.gz: 0d1b3dc8b531417c714f180c74946f7f42fe6470b7a4912567be43f79529cdaad399c4316af05e0ca63b51e37d022f2887e316752d69371afed7c7ca92f0c6d0
7
- data.tar.gz: fb251d9ca04da11c0042f0ec93c908e1ded759faf3c0935a94a7809219cd3ba73d7d4ef7451d6d7293efded29da176af921bcc92607170b5d2219c546559d317
6
+ metadata.gz: 96bfd6336c293999b0aa436b9d63067a7fb50effb8ac8c4bf17a151b80233765dbff782507546053e62e10e5dd49fa64a70d92cb6a47e0acd0cef2c0ff7c5991
7
+ data.tar.gz: c0bbca8dc201efcb927e35e2dc45b39c626a3e81842366b89500b5ca7007a49caa5dee922efd394b987da2f04cd638af03d9573a2fd3df792e8d27f462239770
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ a nice looking [Changelog](http://keepachangelog.com).
5
5
 
6
6
  ## Version [Unreleased]
7
7
 
8
+ ## Version [1.3.0] <small>2019-05-24</small>
9
+
10
+ * Rails 5.2 support
11
+
8
12
  ## Version [1.2.0] <small>2019-04-23</small>
9
13
 
10
14
  * Virtual_delegate :type now specified to avoid rare race conditions with attribute discovery
@@ -30,7 +34,8 @@ a nice looking [Changelog](http://keepachangelog.com).
30
34
  * Initial Release
31
35
  * Extracted from ManageIQ/manageiq
32
36
 
33
- [Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.2.0...HEAD
37
+ [Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.3.0...HEAD
38
+ [1.3.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.2.0...v1.3.0
34
39
  [1.2.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.1.0...v1.2.0
35
40
  [1.1.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.0.0...v1.1.0
36
41
  [1.0.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v0.1.0...v1.0.0
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module VirtualAttributes
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -30,17 +30,29 @@ module ActiveRecord
30
30
  virtual_attribute?(name) || virtual_reflection?(name)
31
31
  end
32
32
 
33
- def remove_virtual_fields(associations)
33
+ def replace_virtual_fields(associations)
34
+ return associations if associations.blank?
35
+
34
36
  case associations
35
37
  when String, Symbol
36
- virtual_field?(associations) ? nil : associations
38
+ virtual_field?(associations) ? replace_virtual_fields(virtual_includes(associations)) : associations
37
39
  when Array
38
- associations.collect { |association| remove_virtual_fields(association) }.compact
40
+ associations.collect { |association| replace_virtual_fields(association) }.compact
39
41
  when Hash
40
42
  associations.each_with_object({}) do |(parent, child), h|
41
- next if virtual_field?(parent)
42
- reflection = reflect_on_association(parent.to_sym)
43
- h[parent] = reflection.nil? || reflection.options[:polymorphic] ? {} : reflection.klass.remove_virtual_fields(child) || {}
43
+ if virtual_field?(parent) # form virtual_attribute => {}
44
+ case (new_includes = replace_virtual_fields(virtual_includes(parent)))
45
+ when String, Symbol
46
+ h[new_includes] = {}
47
+ when Array
48
+ new_includes.each { |association| h[association] = {} }
49
+ when Hash
50
+ h.deep_merge!(new_includes)
51
+ end
52
+ else
53
+ reflection = reflect_on_association(parent.to_sym)
54
+ h[parent] = reflection.nil? || reflection.options[:polymorphic] ? {} : reflection.klass.replace_virtual_fields(child) || {}
55
+ end
44
56
  end
45
57
  else
46
58
  associations
@@ -168,7 +180,7 @@ module ActiveRecord
168
180
 
169
181
  class Relation
170
182
  def without_virtual_includes
171
- filtered_includes = includes_values && klass.remove_virtual_fields(includes_values)
183
+ filtered_includes = includes_values && klass.replace_virtual_fields(includes_values)
172
184
  if filtered_includes != includes_values
173
185
  spawn.tap { |other| other.includes_values = filtered_includes }
174
186
  else
@@ -178,25 +190,12 @@ module ActiveRecord
178
190
 
179
191
  include(Module.new {
180
192
  # From ActiveRecord::FinderMethods
181
- def find_with_associations
193
+ def find_with_associations(&block)
182
194
  real = without_virtual_includes
183
- return super if real.equal?(self)
184
-
185
- if ActiveRecord.version.to_s >= "5.1"
186
- recs, join_dep = real.find_with_associations { |relation, join_dependency| [relation, join_dependency] }
187
- else
188
- recs = real.find_with_associations
189
- end
190
-
191
- if includes_values
192
- ActiveRecord::Associations::Preloader.new.preload(recs, preload_values + includes_values)
193
- end
194
-
195
- # when 5.0 support is dropped, assume a block given
196
- if block_given?
197
- yield recs, join_dep
195
+ if real.equal?(self)
196
+ super
198
197
  else
199
- recs
198
+ real.find_with_associations(&block)
200
199
  end
201
200
  end
202
201
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-virtual_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keenan Brock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord