relation_to_struct 1.7.0 → 1.9.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: f11031515a2afe3d55c8cfb98a664eb984079514c727233c74f341be071a825d
4
- data.tar.gz: 4b97b2856f8529291ea4db5a97bc95b6b58ce5d4b4fbb3eaba066b54a3b317bf
3
+ metadata.gz: 7bb8b931d89b6d73791900b6e8103442856413d8bead16b0f006b28163765ae9
4
+ data.tar.gz: '01867db9481ad85af27892312f23a5f9ceb7687bc7b3232e1c952324be98ab81'
5
5
  SHA512:
6
- metadata.gz: 48ab91406c6acb33100fc8849b2f7ded38ca7a32b199f090d4bd388219b22a615c89f0853d211fa64b2f9b57ba83cf17de4499dc114f2a70578f449c3f389029
7
- data.tar.gz: 9f004fded83df12de47eb94047e0245989f700edd63256af1ee9049b7657126603a0460d49ff54ee1ea67267f4ecfac8b0b7843ee28b8ae33af384ae46b0b53a
6
+ metadata.gz: 6a9aa775119c2e6de109e000591b7dcdd149d5caccc5e3dc145cab69f7e22bc1d142a83bcbb47ccf55f0d2ea9109d44973a7ea6f87226ae46d300b6b6f87e49b
7
+ data.tar.gz: 701affeecbfbce06009babd6d48f6b98622f7de98d7fce6bb3a701c0587845940057ded3661c6e0574a7b7a46ff8003c0f0b7837705263f1377725dae44dd553
@@ -0,0 +1,66 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test_postgres:
5
+ strategy:
6
+ matrix:
7
+ pg:
8
+ - 11
9
+ - 12
10
+ - 13
11
+ - 14
12
+ - 15
13
+ - 16
14
+ ruby:
15
+ - "3.0"
16
+ - "3.1"
17
+ - "3.2"
18
+ gemfile:
19
+ - rails_6_1
20
+ - rails_7_0
21
+ - rails_7_1
22
+ name: PostgreSQL ${{ matrix.pg }} - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }}
23
+ runs-on: ubuntu-latest
24
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
25
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
26
+ ImageOS: ubuntu20
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Start the postgres container
30
+ run: docker-compose up -d
31
+ env:
32
+ PGVERSION: ${{ matrix.pg }}
33
+ - name: Setup Ruby using .ruby-version file
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
38
+ - run: bundle exec rake spec
39
+ env:
40
+ DATABASE: postgresql
41
+ test_sqlite:
42
+ strategy:
43
+ matrix:
44
+ ruby:
45
+ - "3.0"
46
+ - "3.1"
47
+ - "3.2"
48
+ gemfile:
49
+ - rails_6_1
50
+ - rails_7_0
51
+ - rails_7_1
52
+ name: SQLite - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }}
53
+ runs-on: ubuntu-latest
54
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
55
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
56
+ ImageOS: ubuntu20
57
+ steps:
58
+ - uses: actions/checkout@v3
59
+ - name: Setup Ruby using .ruby-version file
60
+ uses: ruby/setup-ruby@v1
61
+ with:
62
+ ruby-version: ${{ matrix.ruby }}
63
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
64
+ - run: bundle exec rake spec
65
+ env:
66
+ DATABASE: sqlite
data/Appraisals CHANGED
@@ -1,10 +1,5 @@
1
- %w(5.0 5.1 5.2 6.0 6.1 7.0).each do |version|
1
+ %w(6.1 7.0 7.1).each do |version|
2
2
  appraise "rails-#{version.gsub(/\./, "-")}" do
3
3
  gem "rails", "~> #{version}.0"
4
- if Gem::Version.new(version) >= Gem::Version.new("6.0.0")
5
- gem "sqlite3", "~> 1.4.0"
6
- else
7
- gem "sqlite3", "~> 1.3.0"
8
- end
9
4
  end
10
5
  end
data/README.md CHANGED
@@ -110,4 +110,4 @@ For this reason, **all methods added to `ActiveRecord::Base` explicitly disable
110
110
 
111
111
  1. Bump version in `lib/relation_to_struct/version.rb` and commit.
112
112
  2. Run `rake build` to build the `*.gem` file.
113
- 3. Run `rake release` to publish the gem to Rubygems.
113
+ 3. Run `rake release` to publish the gem to Rubygems. Note: if while releasing the gem you get the error ``Your rubygems.org credentials aren't set. Run `gem push` to set them.`` you can more simply run `gem signin`.
data/bin/setup ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ bundle exec appraisal install
8
+
9
+ # Do any other automated setup that you need to do here
10
+
11
+ # Launch a blank postgres image
12
+ docker-compose up -d
@@ -0,0 +1,8 @@
1
+ version: "3.3"
2
+ services:
3
+ db:
4
+ image: postgres:${PGVERSION:-16}
5
+ ports:
6
+ - "5432:5432"
7
+ environment:
8
+ - POSTGRES_PASSWORD=${PGPASSWORD:-postgres}
@@ -3,6 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.1.0"
6
- gem "sqlite3", "~> 1.4.0"
7
6
 
8
7
  gemspec path: "../"
@@ -3,6 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 7.0.0"
6
- gem "sqlite3", "~> 1.4.0"
7
6
 
8
7
  gemspec path: "../"
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
6
- gem "sqlite3", "~> 1.3.0"
5
+ gem "rails", "~> 7.1.0"
7
6
 
8
7
  gemspec path: "../"
@@ -1,9 +1,5 @@
1
1
  module RelationToStruct::ActiveRecordBaseExtension
2
2
  module ClassMethods
3
- def _sanitize_sql_for_relation_to_struct(sql)
4
- sanitized_sql = ActiveRecord::VERSION::MAJOR >= 5 ? sanitize_sql(sql) : sanitize_sql(sql, nil)
5
- end
6
-
7
3
  delegate(
8
4
  :structs_from_sql,
9
5
  :pluck_from_sql,
@@ -15,4 +11,4 @@ module RelationToStruct::ActiveRecordBaseExtension
15
11
  end
16
12
  end
17
13
 
18
- ::ActiveRecord::Base.singleton_class.send(:prepend, RelationToStruct::ActiveRecordBaseExtension::ClassMethods)
14
+ ::ActiveRecord::Base.singleton_class.prepend(RelationToStruct::ActiveRecordBaseExtension::ClassMethods)
@@ -1,6 +1,6 @@
1
1
  module RelationToStruct::ActiveRecordConnectionAdapterExtension
2
2
  def structs_from_sql(struct_class, sql, binds=[])
3
- sanitized_sql = ActiveRecord::Base._sanitize_sql_for_relation_to_struct(sql)
3
+ sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
4
4
  result = ActiveRecord::Base.uncached do
5
5
  select_all(sanitized_sql, "Structs SQL Load", binds)
6
6
  end
@@ -25,7 +25,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
25
25
  end
26
26
 
27
27
  def pluck_from_sql(sql, binds=[])
28
- sanitized_sql = ActiveRecord::Base._sanitize_sql_for_relation_to_struct(sql)
28
+ sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
29
29
  result = ActiveRecord::Base.uncached do
30
30
  select_all(sanitized_sql, "Pluck SQL Load", binds)
31
31
  end
@@ -33,7 +33,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
33
33
  end
34
34
 
35
35
  def value_from_sql(sql, binds=[])
36
- sanitized_sql = ActiveRecord::Base._sanitize_sql_for_relation_to_struct(sql)
36
+ sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
37
37
  result = ActiveRecord::Base.uncached do
38
38
  select_all(sanitized_sql, "Value SQL Load", binds)
39
39
  end
@@ -51,7 +51,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
51
51
  end
52
52
 
53
53
  def tuple_from_sql(sql, binds=[])
54
- sanitized_sql = ActiveRecord::Base._sanitize_sql_for_relation_to_struct(sql)
54
+ sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
55
55
  result = ActiveRecord::Base.uncached do
56
56
  select_all(sanitized_sql, "Value SQL Load", binds)
57
57
  end
@@ -68,7 +68,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
68
68
  end
69
69
 
70
70
  def run_sql(sql, binds=[])
71
- sanitized_sql = ActiveRecord::Base._sanitize_sql_for_relation_to_struct(sql)
71
+ sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
72
72
  # We don't need to build a result set unnecessarily; using
73
73
  # interface this also ensures we're clearing the result set
74
74
  # for manually memory managed object (e.g., when using the
@@ -77,4 +77,4 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
77
77
  end
78
78
  end
79
79
 
80
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, RelationToStruct::ActiveRecordConnectionAdapterExtension)
80
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(RelationToStruct::ActiveRecordConnectionAdapterExtension)
@@ -6,12 +6,7 @@ module RelationToStruct::ActiveRecordRelationExtension
6
6
 
7
7
  # See the definition of #pluck in:
8
8
  # activerecord/lib/active_record/relation/calculations.rb
9
- result = nil
10
- if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR < 2
11
- result = klass.connection.select_all(relation.arel, nil, bound_attributes)
12
- else
13
- result = klass.connection.select_all(relation.arel)
14
- end
9
+ result = klass.connection.select_all(relation.arel)
15
10
 
16
11
  if result.columns.size != struct_class.members.size
17
12
  raise ArgumentError, 'Expected struct fields and columns lengths to be equal'
@@ -35,4 +30,4 @@ module RelationToStruct::ActiveRecordRelationExtension
35
30
  end
36
31
  end
37
32
 
38
- ::ActiveRecord::Relation.send(:prepend, RelationToStruct::ActiveRecordRelationExtension)
33
+ ::ActiveRecord::Relation.prepend(RelationToStruct::ActiveRecordRelationExtension)
@@ -1,3 +1,3 @@
1
1
  module RelationToStruct
2
- VERSION = "1.7.0"
2
+ VERSION = "1.9.0"
3
3
  end
@@ -2,6 +2,3 @@ require "relation_to_struct/version"
2
2
  require "relation_to_struct/active_record_connection_adapter_extension"
3
3
  require "relation_to_struct/active_record_base_extension"
4
4
  require "relation_to_struct/active_record_relation_extension"
5
-
6
- module RelationToStruct
7
- end
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "appraisal", ">= 2.1"
22
22
  spec.add_development_dependency "bundler", ">= 1.7"
23
23
  spec.add_development_dependency "rake", ">= 10.0"
24
- spec.add_development_dependency "sqlite3", ">= 1.3"
24
+ spec.add_development_dependency "sqlite3", ">= 1.4"
25
25
  spec.add_development_dependency "rspec", ">= 3.2"
26
26
  spec.add_development_dependency "pry-byebug"
27
27
  spec.add_development_dependency "pg"
28
28
 
29
- spec.add_dependency "activerecord", ">= 5.0", "< 7.1"
30
- spec.add_dependency "activesupport", ">= 5.0", "< 7.1"
29
+ spec.add_dependency "activerecord", ">= 6.1", "< 7.2"
30
+ spec.add_dependency "activesupport", ">= 6.1", "< 7.2"
31
31
  end
@@ -4,8 +4,8 @@ ActiveRecord::Base.configurations = {
4
4
  "host" => 'localhost',
5
5
  "database" => 'relation_to_struct_tests',
6
6
  "encoding" => 'utf8',
7
- "username" => ENV["DATABASE_POSTGRESQL_USERNAME"] || `whoami`.strip,
8
- "password" => ENV["DATABASE_POSTGRESQL_PASSWORD"],
7
+ "username" => ENV["PGUSER"] || 'postgres',
8
+ "password" => ENV["PGPASSWORD"] || 'postgres',
9
9
  },
10
10
  "sqlite" => {
11
11
  "adapter" => "sqlite3",
@@ -14,12 +14,7 @@ ActiveRecord::Base.configurations = {
14
14
  }
15
15
 
16
16
  env = ENV['DATABASE'] ||= 'sqlite'
17
- config =
18
- if ActiveRecord::VERSION::MAJOR < 7
19
- ActiveRecord::Base.configurations[env]
20
- else
21
- ActiveRecord::Base.configurations.configs_for(env_name: env).first
22
- end
17
+ config = ActiveRecord::Base.configurations.configs_for(env_name: env).first
23
18
 
24
19
  case env
25
20
  when 'postgresql'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relation_to_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coleman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2023-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: '1.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: '1.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,47 +114,49 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '5.0'
117
+ version: '6.1'
118
118
  - - "<"
119
119
  - !ruby/object:Gem::Version
120
- version: '7.1'
120
+ version: '7.2'
121
121
  type: :runtime
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: '5.0'
127
+ version: '6.1'
128
128
  - - "<"
129
129
  - !ruby/object:Gem::Version
130
- version: '7.1'
130
+ version: '7.2'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: activesupport
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '5.0'
137
+ version: '6.1'
138
138
  - - "<"
139
139
  - !ruby/object:Gem::Version
140
- version: '7.1'
140
+ version: '7.2'
141
141
  type: :runtime
142
142
  prerelease: false
143
143
  version_requirements: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: '5.0'
147
+ version: '6.1'
148
148
  - - "<"
149
149
  - !ruby/object:Gem::Version
150
- version: '7.1'
150
+ version: '7.2'
151
151
  description: ''
152
152
  email:
153
153
  - jtc331@gmail.com
154
- executables: []
154
+ executables:
155
+ - setup
155
156
  extensions: []
156
157
  extra_rdoc_files: []
157
158
  files:
159
+ - ".github/workflows/ci.yml"
158
160
  - ".gitignore"
159
161
  - ".rspec"
160
162
  - Appraisals
@@ -162,12 +164,11 @@ files:
162
164
  - LICENSE.txt
163
165
  - README.md
164
166
  - Rakefile
165
- - gemfiles/rails_5_0.gemfile
166
- - gemfiles/rails_5_1.gemfile
167
- - gemfiles/rails_5_2.gemfile
168
- - gemfiles/rails_6_0.gemfile
167
+ - bin/setup
168
+ - docker-compose.yml
169
169
  - gemfiles/rails_6_1.gemfile
170
170
  - gemfiles/rails_7_0.gemfile
171
+ - gemfiles/rails_7_1.gemfile
171
172
  - lib/relation_to_struct.rb
172
173
  - lib/relation_to_struct/active_record_base_extension.rb
173
174
  - lib/relation_to_struct/active_record_connection_adapter_extension.rb
@@ -187,7 +188,7 @@ homepage: ''
187
188
  licenses:
188
189
  - MIT
189
190
  metadata: {}
190
- post_install_message:
191
+ post_install_message:
191
192
  rdoc_options: []
192
193
  require_paths:
193
194
  - lib
@@ -203,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  version: '0'
204
205
  requirements: []
205
206
  rubygems_version: 3.1.6
206
- signing_key:
207
+ signing_key:
207
208
  specification_version: 4
208
209
  summary: Return struct results from ActiveRecord relation queries
209
210
  test_files:
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.1.0"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.2.0"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 6.0.0"
6
- gem "sqlite3", "~> 1.4.0"
7
-
8
- gemspec path: "../"