activerecord-virtual_attributes 6.1.0 → 6.1.1

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: eb60079c2b76281f9ace2d7f4a25c9956d9c439c408b6d0df615cb8c4512a31f
4
- data.tar.gz: 6eb95ac5ea930cd875c73e8fcfaca826e3f69370417489f9c074c2c90795e71e
3
+ metadata.gz: 8a35d6c7665469341b76ae68e1a84180ccef887c47f56b7000efc2f0024d0a93
4
+ data.tar.gz: ba57d73a5034e461d3c6bd77a50eb5475d1fe0dab8c3332f91142c893fa736a2
5
5
  SHA512:
6
- metadata.gz: e0d8221e8ee5ce87f5082c7e3e7b821375e0da1c6109bd772c1ee01fb396de12169c3f6ac53cdddd267d7974785b81ca0047ccf4b0ed43278b79bdb84c2cd557
7
- data.tar.gz: 0b980f5df648db206618fd304ac54fd69f84ed53e004226629ddcc389775686934291baaf106cf196b0fe5204107046bf437f6db12b41a632a62dba88c71b0a0
6
+ metadata.gz: 55f8e509034dc3a13dae283733da176c308d25538c38595cebfd98008d07be372c0843752e547be6afb5af361fd1610900f05fc52cdcdfbd8bff834b66233060
7
+ data.tar.gz: c4511ba748f911a985f308bdfa61f9d6c64c57ec1245003dea509205f3aa4e0085f20f7e9adb5674d3657d750c34e6c4d64d41ee5faebb18846c9e8ef3ea4c32
@@ -1,6 +1,10 @@
1
1
  name: CI
2
2
 
3
- on: [push, pull_request]
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
- # for the pg cli (psql, pg_isready) and possibly rails
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 Postgres tests
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
- - if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '2.7' }}
70
- name: Report code coverage
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
- Versioning of this gem follows ActiveRecord versioning, and does not follow SemVer.
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
- e.g.: virtual attributes 6.1.x supports all versions of rails 6.1.
5
+ ## [Unreleased]
6
6
 
7
- Use the latest version of both this gem and rails where the first 2 digits match.
7
+ ## [6.1.1] - 2022-08-09
8
8
 
9
- ## [Unreleased]
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.0...HEAD
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:
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module VirtualAttributes
3
- VERSION = "6.1.0".freeze
3
+ VERSION = "6.1.1".freeze
4
4
  end
5
5
  end
@@ -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.0
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-02-03 00:00:00.000000000 Z
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.3.5
170
+ rubygems_version: 3.1.6
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Access non-sql attributes from sql