activerecord-virtual_attributes 6.1.0 → 6.1.1
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/.github/workflows/ci.yaml +13 -18
- data/CHANGELOG.md +6 -5
- data/README.md +6 -0
- data/lib/active_record/virtual_attributes/version.rb +1 -1
- data/lib/active_record/virtual_attributes/virtual_arel.rb +62 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a35d6c7665469341b76ae68e1a84180ccef887c47f56b7000efc2f0024d0a93
|
4
|
+
data.tar.gz: ba57d73a5034e461d3c6bd77a50eb5475d1fe0dab8c3332f91142c893fa736a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f8e509034dc3a13dae283733da176c308d25538c38595cebfd98008d07be372c0843752e547be6afb5af361fd1610900f05fc52cdcdfbd8bff834b66233060
|
7
|
+
data.tar.gz: c4511ba748f911a985f308bdfa61f9d6c64c57ec1245003dea509205f3aa4e0085f20f7e9adb5674d3657d750c34e6c4d64d41ee5faebb18846c9e8ef3ea4c32
|
data/.github/workflows/ci.yaml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
schedule:
|
7
|
+
- cron: '0 0 * * 0'
|
4
8
|
|
5
9
|
jobs:
|
6
10
|
ci:
|
@@ -15,27 +19,20 @@ jobs:
|
|
15
19
|
env:
|
16
20
|
POSTGRES_PASSWORD: password
|
17
21
|
POSTGRES_DB: virtual_attributes
|
22
|
+
options: --health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 5
|
18
23
|
ports:
|
19
24
|
- 5432:5432
|
20
|
-
options: >-
|
21
|
-
--health-cmd pg_isready
|
22
|
-
--health-interval 2s
|
23
|
-
--health-timeout 5s
|
24
|
-
--health-retries 5
|
25
25
|
mysql:
|
26
26
|
image: mysql:8.0
|
27
27
|
env:
|
28
28
|
MYSQL_ROOT_PASSWORD: password
|
29
29
|
MYSQL_DATABASE: virtual_attributes
|
30
|
+
options: --health-cmd="mysqladmin ping -h 127.0.0.1 -P 3306 --silent" --health-interval 10s --health-timeout 5s --health-retries 3
|
30
31
|
ports:
|
31
32
|
- 3306:3306
|
32
|
-
options: >-
|
33
|
-
--health-cmd="mysqladmin ping -h 127.0.0.1 -P 3306 --silent"
|
34
|
-
--health-interval 10s
|
35
|
-
--health-timeout 5s
|
36
|
-
--health-retries 3
|
37
33
|
env:
|
38
|
-
|
34
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
35
|
+
# for the pg cli (psql, pg_isready) and rails
|
39
36
|
PGHOST: localhost
|
40
37
|
PGPORT: 5432
|
41
38
|
PGUSER: postgres
|
@@ -50,24 +47,22 @@ jobs:
|
|
50
47
|
with:
|
51
48
|
ruby-version: ${{ matrix.ruby-version }}
|
52
49
|
bundler-cache: true
|
50
|
+
timeout-minutes: 30
|
53
51
|
- name: Run SQLite tests
|
54
52
|
env:
|
55
53
|
DB: sqlite3
|
56
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
57
54
|
run: bundle exec rake
|
58
|
-
- name: Run
|
55
|
+
- name: Run PostgreSQL tests
|
59
56
|
env:
|
60
57
|
DB: pg
|
61
58
|
COLLATE_SYMBOLS: false
|
62
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
63
59
|
run: bundle exec rake
|
64
60
|
- name: Run MySQL tests
|
65
61
|
env:
|
66
62
|
DB: mysql2
|
67
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
68
63
|
run: bundle exec rake
|
69
|
-
-
|
70
|
-
|
64
|
+
- name: Report code coverage
|
65
|
+
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '2.7' }}
|
71
66
|
continue-on-error: true
|
72
67
|
uses: paambaati/codeclimate-action@v3.0.0
|
73
68
|
env:
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
|
3
|
+
The versioning of this gem follows ActiveRecord versioning, and does not follow SemVer. See the [README](./README.md) for more details.
|
4
4
|
|
5
|
-
|
5
|
+
## [Unreleased]
|
6
6
|
|
7
|
-
|
7
|
+
## [6.1.1] - 2022-08-09
|
8
8
|
|
9
|
-
|
9
|
+
* fix HomogeneousIn clauses [#111](https://github.com/ManageIQ/activerecord-virtual_attributes/pull/111)
|
10
10
|
|
11
11
|
## [6.1.0] - 2022-02-03
|
12
12
|
|
@@ -86,7 +86,8 @@ Use the latest version of both this gem and rails where the first 2 digits match
|
|
86
86
|
* Initial Release
|
87
87
|
* Extracted from ManageIQ/manageiq
|
88
88
|
|
89
|
-
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v6.1.
|
89
|
+
[Unreleased]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v6.1.1...HEAD
|
90
|
+
[6.1.1]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v6.1.0...v6.1.1
|
90
91
|
[6.1.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v3.0.0...v6.1.0
|
91
92
|
[3.0.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v2.0.0...v3.0.0
|
92
93
|
[2.0.0]: https://github.com/ManageIQ/activerecord-virtual_attributes/compare/v1.6.0...v2.0.0
|
data/README.md
CHANGED
@@ -12,6 +12,12 @@ This gem allows you to represent these attributes in sql so `ORDER BY` `WHERE` c
|
|
12
12
|
|
13
13
|
This also allows you to calculate counts and treat those as a field accessible with `select(:child_count)` to get rid of the N+1 problem of running a `count(*)` on a subcollection for each row.
|
14
14
|
|
15
|
+
## Versioning
|
16
|
+
|
17
|
+
As of v6.1.0, the versioning of this gem follows ActiveRecord versioning, and does not follow SemVer (e.g. virtual attributes v6.1.x supports all versions of Rails 6.1). Version v3.0.0 supports Rails 6.0 and lower.
|
18
|
+
|
19
|
+
Use the latest version of both this gem and Rails where the first 2 digits match.
|
20
|
+
|
15
21
|
## Installation
|
16
22
|
|
17
23
|
Add this line to your application's Gemfile:
|
@@ -12,7 +12,27 @@ module ActiveRecord
|
|
12
12
|
|
13
13
|
# in essence, this is our Arel::Nodes::VirtualAttribute
|
14
14
|
class Arel::Nodes::Grouping
|
15
|
-
attr_accessor :name
|
15
|
+
attr_accessor :name, :relation
|
16
|
+
|
17
|
+
# methods from Arel::Nodes::Attribute
|
18
|
+
def type_caster
|
19
|
+
relation.type_for_attribute(name)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a node for lowering this attribute
|
23
|
+
def lower
|
24
|
+
relation.lower(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def type_cast_for_database(value)
|
28
|
+
relation.type_cast_for_database(name, value)
|
29
|
+
end
|
30
|
+
|
31
|
+
# rubocop:disable Rails/Delegate
|
32
|
+
def able_to_type_cast?
|
33
|
+
relation.able_to_type_cast?
|
34
|
+
end
|
35
|
+
# rubocop:enable Rails/Delegate
|
16
36
|
end
|
17
37
|
|
18
38
|
module VirtualArel
|
@@ -86,6 +106,7 @@ module ActiveRecord
|
|
86
106
|
arel = arel_lambda.call(table)
|
87
107
|
arel = Arel::Nodes::Grouping.new(arel) unless arel.kind_of?(Arel::Nodes::Grouping)
|
88
108
|
arel.name = column_name
|
109
|
+
arel.relation = table
|
89
110
|
arel
|
90
111
|
end
|
91
112
|
|
@@ -98,3 +119,43 @@ module ActiveRecord
|
|
98
119
|
end
|
99
120
|
end
|
100
121
|
end
|
122
|
+
|
123
|
+
module Arel # :nodoc: all
|
124
|
+
# rubocop:disable Naming/MethodName
|
125
|
+
# rubocop:disable Naming/MethodParameterName
|
126
|
+
# rubocop:disable Style/ConditionalAssignment
|
127
|
+
module Visitors
|
128
|
+
# rails 6.1...
|
129
|
+
class ToSql
|
130
|
+
private
|
131
|
+
|
132
|
+
def visit_Arel_Nodes_HomogeneousIn(o, collector)
|
133
|
+
collector.preparable = false
|
134
|
+
|
135
|
+
# change:
|
136
|
+
# See https://github.com/rails/rails/pull/45642
|
137
|
+
visit(o.left, collector)
|
138
|
+
# /change
|
139
|
+
|
140
|
+
if o.type == :in
|
141
|
+
collector << " IN ("
|
142
|
+
else
|
143
|
+
collector << " NOT IN ("
|
144
|
+
end
|
145
|
+
|
146
|
+
values = o.casted_values
|
147
|
+
|
148
|
+
if values.empty?
|
149
|
+
collector << @connection.quote(nil)
|
150
|
+
else
|
151
|
+
collector.add_binds(values, o.proc_for_binds, &bind_block)
|
152
|
+
end
|
153
|
+
|
154
|
+
collector << ")"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
# rubocop:enable Naming/MethodName
|
159
|
+
# rubocop:enable Naming/MethodParameterName
|
160
|
+
# rubocop:enable Style/ConditionalAssignment
|
161
|
+
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: 6.1.
|
4
|
+
version: 6.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keenan Brock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.1.6
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Access non-sql attributes from sql
|