relation_to_struct 1.6.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
- SHA1:
3
- metadata.gz: d1ffdbfc2950c798cd223660370ca62ee6a8128b
4
- data.tar.gz: 246947abe7a8f85d6c2558a3b33a0b027547ada4
2
+ SHA256:
3
+ metadata.gz: 7bb8b931d89b6d73791900b6e8103442856413d8bead16b0f006b28163765ae9
4
+ data.tar.gz: '01867db9481ad85af27892312f23a5f9ceb7687bc7b3232e1c952324be98ab81'
5
5
  SHA512:
6
- metadata.gz: 25ef491ea1f470beea129c8e1d5f92308773092ef470afaadedd56ec9046ad1950d4192e1e61efa816966ecf0dc5eafe40c23bc33ed0572424d0c82368d6cbdf
7
- data.tar.gz: 8a8f2eebe3192ae4d3947a309adfd476e903af1bc754496d1f53f03d8040afb8ad12f12f640a4f69dcc54179b015b02399a19b2d712420b0dabed21fff561c2a
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).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 version[0] == '6'
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}
@@ -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", "~> 6.1.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.1.0"
6
- gem "sqlite3", "~> 1.3.0"
5
+ gem "rails", "~> 7.0.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.2.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.6.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"
30
- spec.add_dependency "activesupport", ">= 5.0", "< 7"
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,7 +14,7 @@ ActiveRecord::Base.configurations = {
14
14
  }
15
15
 
16
16
  env = ENV['DATABASE'] ||= 'sqlite'
17
- config = ActiveRecord::Base.configurations[env]
17
+ config = ActiveRecord::Base.configurations.configs_for(env_name: env).first
18
18
 
19
19
  case env
20
20
  when 'postgresql'
@@ -57,7 +57,7 @@ describe ActiveRecord::Relation do
57
57
  it 'properly casts values from arbitrary calculated columns' do
58
58
  hayek = Economist.create!(name: 'F.A. Hayek')
59
59
  scope = Economist.all
60
- pluck_results = scope.pluck("date('now')")
60
+ pluck_results = scope.pluck(Arel.sql("date('now')"))
61
61
  pluck_column_klass = pluck_results.first.class
62
62
 
63
63
  date_struct = Struct.new(:date)
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ def active_record_supports_arrays?
14
14
  Economist.create!(name: 'F.A. Hayek')
15
15
  Economist.create!(name: 'Ludwig von Mises')
16
16
 
17
- pluck_results = Economist.select('name').order('id').limit(1).pluck('array[name]') rescue nil
17
+ pluck_results = Economist.select('name').order('id').limit(1).pluck(Arel.sql('array[name]')) rescue nil
18
18
  if pluck_results
19
19
  raise StandardError, "Unexpected array query results" unless pluck_results == [['F.A. Hayek']] # Verify ActiveRecord interface.
20
20
  supports_arrays = true
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.6.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coleman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 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'
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'
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'
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'
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,10 +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
+ - gemfiles/rails_6_1.gemfile
170
+ - gemfiles/rails_7_0.gemfile
171
+ - gemfiles/rails_7_1.gemfile
169
172
  - lib/relation_to_struct.rb
170
173
  - lib/relation_to_struct/active_record_base_extension.rb
171
174
  - lib/relation_to_struct/active_record_connection_adapter_extension.rb
@@ -200,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
203
  - !ruby/object:Gem::Version
201
204
  version: '0'
202
205
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.5.2.3
206
+ rubygems_version: 3.1.6
205
207
  signing_key:
206
208
  specification_version: 4
207
209
  summary: Return struct results from ActiveRecord relation queries
@@ -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: "../"