activerecord-virtual_attributes 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +30 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_cc.yml +4 -0
- data/.rubocop_local.yml +0 -0
- data/.travis.yml +21 -20
- data/CHANGELOG.md +9 -1
- data/README.md +7 -1
- data/activerecord-virtual_attributes.gemspec +1 -0
- data/lib/active_record/virtual_attributes/version.rb +1 -1
- data/lib/active_record/virtual_attributes/virtual_fields.rb +9 -5
- data/lib/active_record/virtual_attributes.rb +9 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f8bd112296732146d0d98ed5f2f490b6d72361bc965d16d092f0712d6061767
|
4
|
+
data.tar.gz: 5dbbc67687d1143f69f18292f2cbdefe5166b69c8e034d5050cd2d203730ac5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd7ab60cefbb59e9c77f197f755822e530d95e52fc67fb0f9eea261473abfae8a34713957e756fa328c2128982a3af344eae629d5d3b9b8bdaec14f671985a07
|
7
|
+
data.tar.gz: a08eecd9ed665f9276fe098a95108df2d7e566751b6a8e0ed5ca39d34738a3dd5638df1e33517f41b6016ae446c4cb470dac1ed49c2a48613c7f515c8c72ec7b
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
version: '2'
|
3
|
+
prepare:
|
4
|
+
fetch:
|
5
|
+
- url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
|
6
|
+
path: ".rubocop_base.yml"
|
7
|
+
- url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml
|
8
|
+
path: ".rubocop_cc_base.yml"
|
9
|
+
checks:
|
10
|
+
argument-count:
|
11
|
+
enabled: false
|
12
|
+
complex-logic:
|
13
|
+
enabled: false
|
14
|
+
file-lines:
|
15
|
+
enabled: false
|
16
|
+
method-complexity:
|
17
|
+
config:
|
18
|
+
threshold: 11
|
19
|
+
method-count:
|
20
|
+
enabled: false
|
21
|
+
method-lines:
|
22
|
+
enabled: false
|
23
|
+
nested-control-flow:
|
24
|
+
enabled: false
|
25
|
+
return-statements:
|
26
|
+
enabled: false
|
27
|
+
plugins:
|
28
|
+
rubocop:
|
29
|
+
enabled: true
|
30
|
+
config: ".rubocop_cc.yml"
|
data/.rubocop.yml
ADDED
data/.rubocop_cc.yml
ADDED
data/.rubocop_local.yml
ADDED
File without changes
|
data/.travis.yml
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
---
|
2
|
-
sudo: false
|
3
2
|
language: ruby
|
4
|
-
|
5
|
-
# bundler: true
|
3
|
+
cache: bundler
|
6
4
|
rvm:
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
- 2.4.1
|
6
|
+
- 2.5.3
|
10
7
|
services:
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
- postgresql
|
9
|
+
- mysql
|
14
10
|
env:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
- DB=sqlite3
|
12
|
+
- DB=pg
|
13
|
+
- DB=mysql2
|
19
14
|
gemfile:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
- gemfiles/virtual_attributes_50.gemfile
|
16
|
+
- gemfiles/virtual_attributes_51.gemfile
|
17
|
+
#- gemfiles/virtual_attributes_52.gemfile
|
18
|
+
before_install:
|
19
|
+
- 'echo ''gem: --no-ri --no-rdoc --no-document'' > ~/.gemrc'
|
25
20
|
before_script:
|
26
|
-
|
27
|
-
|
21
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
22
|
+
> ./cc-test-reporter
|
23
|
+
- chmod +x ./cc-test-reporter
|
24
|
+
- "./cc-test-reporter before-build"
|
25
|
+
- sh -c "if [ '$DB' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS virtual_attributes;' ; psql -c ' CREATE DATABASE virtual_attributes;' ; fi"
|
26
|
+
- sh -c "if [ '$DB' = 'mysql2' ]; then mysql -e 'DROP DATABASE IF EXISTS virtual_attributes; CREATE DATABASE virtual_attributes;'; fi"
|
27
|
+
after_script:
|
28
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
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.1.0] <small>2019-04-23</small>
|
9
|
+
|
10
|
+
* add legacy types for VirtualAttribute::Types
|
11
|
+
* fix rails 5.1 bug with includes
|
12
|
+
* remove reference to MiqPreloader
|
13
|
+
* climate code fixes
|
14
|
+
|
8
15
|
## Version [1.0.0] <small>2019-03-05</small>
|
9
16
|
|
10
17
|
* renamed to activerecord-virtual_attributes
|
@@ -16,5 +23,6 @@ a nice looking [Changelog](http://keepachangelog.com).
|
|
16
23
|
* Initial Release
|
17
24
|
* Extracted from ManageIQ/manageiq
|
18
25
|
|
19
|
-
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.
|
26
|
+
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.1.0...HEAD
|
27
|
+
[1.1.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.0.0...v1.1.0
|
20
28
|
[1.0.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v0.1.0...v1.0.0
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# VirtualAttributes
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/ManageIQ/activerecord-virtual_attributes.svg?branch=master)](https://travis-ci.org/ManageIQ/activerecord-virtual_attributes)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/e1a0c26941c00f4edb55/maintainability)](https://codeclimate.com/github/ManageIQ/activerecord-virtual_attributes/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/e1a0c26941c00f4edb55/test_coverage)](https://codeclimate.com/github/ManageIQ/activerecord-virtual_attributes/test_coverage)
|
6
|
+
[![Security](https://hakiri.io/github/ManageIQ/activerecord-virtual_attributes/master.svg)](https://hakiri.io/github/ManageIQ/activerecord-virtual_attributes/master)
|
7
|
+
|
3
8
|
This allows you to define a ruby method that acts like an attribute or relation.
|
4
9
|
|
5
10
|
Sometimes you have a model with an attribute defined in ruby, but you want to sort by it or filter by it.
|
@@ -43,4 +48,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Manage
|
|
43
48
|
|
44
49
|
## License
|
45
50
|
|
46
|
-
|
51
|
+
This project is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
52
|
+
|
@@ -58,7 +58,7 @@ module ActiveRecord
|
|
58
58
|
|
59
59
|
module Associations
|
60
60
|
class Preloader
|
61
|
-
prepend
|
61
|
+
prepend(Module.new {
|
62
62
|
def preloaders_for_one(association, records, scope)
|
63
63
|
klass_map = records.compact.group_by(&:class)
|
64
64
|
|
@@ -67,14 +67,14 @@ module ActiveRecord
|
|
67
67
|
preload(subset, virtuals)
|
68
68
|
end
|
69
69
|
|
70
|
-
records_with_association = klass_map.select { |k,
|
70
|
+
records_with_association = klass_map.select { |k, _rs| k.reflect_on_association(association) }.flat_map { |_k, rs| rs }
|
71
71
|
if records_with_association.any?
|
72
72
|
loaders.concat(super(association, records_with_association, scope))
|
73
73
|
end
|
74
74
|
|
75
75
|
loaders
|
76
76
|
end
|
77
|
-
}
|
77
|
+
})
|
78
78
|
end
|
79
79
|
|
80
80
|
# FIXME: Hopefully we can get this into Rails core so this is no longer
|
@@ -187,13 +187,17 @@ module ActiveRecord
|
|
187
187
|
else
|
188
188
|
recs = real.find_with_associations
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
|
+
if includes_values
|
192
|
+
ActiveRecord::Associations::Preloader.new.preload(recs, preload_values + includes_values)
|
193
|
+
end
|
191
194
|
|
192
195
|
# when 5.0 support is dropped, assume a block given
|
193
196
|
if block_given?
|
194
197
|
yield recs, join_dep
|
198
|
+
else
|
199
|
+
recs
|
195
200
|
end
|
196
|
-
recs
|
197
201
|
end
|
198
202
|
|
199
203
|
# From ActiveRecord::QueryMethods
|
@@ -141,3 +141,12 @@ end
|
|
141
141
|
|
142
142
|
require "active_record/virtual_attributes/virtual_total"
|
143
143
|
require "active_record/virtual_attributes/arel_groups"
|
144
|
+
|
145
|
+
# legacy support for sql types
|
146
|
+
module VirtualAttributes
|
147
|
+
module Type
|
148
|
+
Symbol = ActiveRecord::VirtualAttributes::Type::Symbol
|
149
|
+
StringSet = ActiveRecord::VirtualAttributes::Type::StringSet
|
150
|
+
NumericSet = ActiveRecord::VirtualAttributes::Type::NumericSet
|
151
|
+
end
|
152
|
+
end
|
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.1.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-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Define attributes in arel
|
70
84
|
email:
|
71
85
|
- keenan@thebrocks.net
|
@@ -73,8 +87,12 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".codeclimate.yml"
|
76
91
|
- ".gitignore"
|
77
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".rubocop_cc.yml"
|
95
|
+
- ".rubocop_local.yml"
|
78
96
|
- ".travis.yml"
|
79
97
|
- Appraisals
|
80
98
|
- CHANGELOG.md
|