activerecord-virtual_attributes 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/activerecord-virtual_attributes.gemspec +1 -0
- data/bin/console +4 -7
- data/init.rb +1 -1
- data/lib/active_record/virtual_attributes/version.rb +1 -1
- data/lib/active_record/virtual_attributes/virtual_fields.rb +39 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12889257087183346e6a2d382f1105adcd42dcf0d56e8cfb3174ad9bc03e93a4
|
4
|
+
data.tar.gz: 422aa8fc3a9115014feca968087c32f52641daaaab04db3308fe7382377b6b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92c23a0d47b390b39c1576e28ae444891dc7c4fda8b4ee493541d760aa7784442b6be95ea5f4dbd7d742feec949defd5640a5b923c755aa8162076a3fdd0700b
|
7
|
+
data.tar.gz: f2ee6541b6b0aaa5dcd6d25e2019bbd97ead4276495f688e71ff614463a1c818f12106a38bfb13c801e91880c8910fecd71878d9aee23f7e4c6d178010e06d91
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,13 @@ a nice looking [Changelog](http://keepachangelog.com).
|
|
5
5
|
|
6
6
|
## Version [Unreleased]
|
7
7
|
|
8
|
+
## Version [1.4.0] <small>2019-07-13</small>
|
9
|
+
|
10
|
+
* fix includes to include all associations
|
11
|
+
* fix bin/console to now actually run
|
12
|
+
* select no longer munges field attribute
|
13
|
+
* support virtual attributes in left_outer_joins
|
14
|
+
|
8
15
|
## Version [1.3.1] <small>2019-06-06</small>
|
9
16
|
|
10
17
|
* quote column aliases
|
@@ -38,7 +45,8 @@ a nice looking [Changelog](http://keepachangelog.com).
|
|
38
45
|
* Initial Release
|
39
46
|
* Extracted from ManageIQ/manageiq
|
40
47
|
|
41
|
-
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.
|
48
|
+
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.4.0...HEAD
|
49
|
+
[1.4.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.3.1...v1.4.0
|
42
50
|
[1.3.1]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.3.0...v1.3.1
|
43
51
|
[1.3.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.2.0...v1.3.0
|
44
52
|
[1.2.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.1.0...v1.2.0
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency "activerecord", ">= 5.0"
|
29
29
|
|
30
30
|
spec.add_development_dependency "appraisal"
|
31
|
+
spec.add_development_dependency "byebug"
|
31
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
34
|
spec.add_development_dependency "simplecov"
|
data/bin/console
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "virtual_attributes"
|
4
|
+
require "active_record-virtual_attributes"
|
5
5
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
6
|
+
# models for local testing
|
7
|
+
require "rspec"
|
8
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
12
9
|
|
13
10
|
require "irb"
|
14
11
|
IRB.start(__FILE__)
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'virtual_attributes'
|
1
|
+
require 'active_record-virtual_attributes'
|
@@ -50,18 +50,46 @@ module ActiveRecord
|
|
50
50
|
if virtual_field?(parent) # form virtual_attribute => {}
|
51
51
|
case (new_includes = replace_virtual_fields(virtual_includes(parent)))
|
52
52
|
when String, Symbol
|
53
|
-
h
|
53
|
+
merge_includes(h, new_includes)
|
54
54
|
when Array
|
55
|
-
|
55
|
+
merge_includes(h, new_includes)
|
56
56
|
when Hash
|
57
|
-
h
|
57
|
+
merge_includes(h, new_includes)
|
58
58
|
end
|
59
59
|
else
|
60
60
|
reflection = reflect_on_association(parent.to_sym)
|
61
|
-
|
61
|
+
new_child = reflection.nil? || reflection.options[:polymorphic] ? {} : reflection.klass.replace_virtual_fields(child) || {}
|
62
|
+
merge_includes(h, parent => new_child)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
67
|
+
# @param [Hash, Array, String, Symbol] value
|
68
|
+
# @return [Hash]
|
69
|
+
def include_to_hash(value)
|
70
|
+
case value
|
71
|
+
when String, Symbol
|
72
|
+
{value => {}}
|
73
|
+
when Array
|
74
|
+
value.flatten.each_with_object({}) { |k, h| h[k] = {} }
|
75
|
+
when nil
|
76
|
+
{}
|
77
|
+
else
|
78
|
+
value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param [Hash] hash1
|
83
|
+
# @param [Hash] hash2
|
84
|
+
def merge_includes(hash1, hash2)
|
85
|
+
return hash1 if hash2.blank?
|
86
|
+
|
87
|
+
hash1 = include_to_hash(hash1)
|
88
|
+
hash2 = include_to_hash(hash2)
|
89
|
+
hash1.deep_merge!(hash2) do |_k, v1, v2|
|
90
|
+
merge_includes(v1, v2)
|
91
|
+
end
|
92
|
+
end
|
65
93
|
end
|
66
94
|
end
|
67
95
|
end
|
@@ -209,8 +237,7 @@ module ActiveRecord
|
|
209
237
|
# support virtual attributes by adding an alias to the sql phrase for the column
|
210
238
|
# it does not add an as() if the column already has an as
|
211
239
|
# this code is based upon _select()
|
212
|
-
fields.flatten!
|
213
|
-
fields.map! do |field|
|
240
|
+
fields = fields.flatten.map! do |field|
|
214
241
|
if virtual_attribute?(field) && (arel = klass.arel_attribute(field)) && arel.respond_to?(:as)
|
215
242
|
arel.as(connection.quote_column_name(field.to_s))
|
216
243
|
else
|
@@ -221,6 +248,12 @@ module ActiveRecord
|
|
221
248
|
super
|
222
249
|
end
|
223
250
|
|
251
|
+
# From ActiveRecord::QueryMethods
|
252
|
+
def build_left_outer_joins(manager, outer_joins, *rest)
|
253
|
+
outer_joins = klass.replace_virtual_fields(outer_joins)
|
254
|
+
super if outer_joins.present?
|
255
|
+
end
|
256
|
+
|
224
257
|
# From ActiveRecord::Calculations
|
225
258
|
def calculate(operation, attribute_name)
|
226
259
|
# work around 1 until https://github.com/rails/rails/pull/25304 gets merged
|
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.
|
4
|
+
version: 1.4.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-
|
11
|
+
date: 2019-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|