relation_to_struct 1.2.2 → 1.3.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
  SHA1:
3
- metadata.gz: 7e144536f0414aeccfb958f8ccf336ecec3bc3e8
4
- data.tar.gz: d5c5785c24474b4629081346ef5f1c2eb1620ffd
3
+ metadata.gz: f3c97c2553a7d275a6830b61306a9980db46f98c
4
+ data.tar.gz: d466c23b0d22e28fd1892314f35bc547d913425d
5
5
  SHA512:
6
- metadata.gz: 0eede8794be139c326deca580ec817adffe746454848af34ee701e7a540d97267e6de44d0b9245c8f7128335b574013a2bea1fdb6c12f750c497f51cc49f47dc
7
- data.tar.gz: 9b7e3a0e055c2501d7d5c23eb11bc08727d71a008f382580c328d746e43037d2c7791094acee393381ec8da822971ee3ec7679d1877b0c9bd2b9efb4b86d3b90
6
+ metadata.gz: 4885ef40deeb19798257eca384395bf7469f8e5363b05019e2fc64b99e711d6988755198b55a1c6f9da279f0dc7499e8569d0eccdbaf15d676ff66fcbaad6234
7
+ data.tar.gz: 96f902d4a3259653b5c6f9288655728f588202cffb0b8c941172797b063395abedd9e6d97283a4705d5f70b3e63fd901127ba6902574787ee8ab08d3d5478bb4
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  *.so
13
13
  *.o
14
14
  *.a
15
+ .ruby-version
15
16
  mkmf.log
data/Appraisals CHANGED
@@ -1,5 +1,5 @@
1
- %w(4.1 4.2 5.0 5.1).each do |version|
1
+ %w(5.0 5.1).each do |version|
2
2
  appraise "rails-#{version.gsub(/\./, "-")}" do
3
- gem "rails", "~> #{version}.0"
3
+ gem "rails", "~> #{version}"
4
4
  end
5
5
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
5
+ gem "rails", "~> 5.0"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.1.0"
5
+ gem "rails", "~> 5.1"
6
6
 
7
7
  gemspec path: "../"
@@ -1,7 +1,6 @@
1
1
  require "relation_to_struct/version"
2
2
  require "relation_to_struct/active_record_base_extension"
3
3
  require "relation_to_struct/active_record_relation_extension"
4
- require "relation_to_struct/active_record_result_41_extension"
5
4
 
6
5
  module RelationToStruct
7
6
  end
@@ -5,7 +5,10 @@ module RelationToStruct::ActiveRecordRelationExtension
5
5
  raise ArgumentError, 'Expected select_values to be present' unless self.select_values.present?
6
6
 
7
7
  relation = spawn
8
- result = klass.connection.select_all(relation.arel, nil, relation.arel.bind_values + bind_values)
8
+
9
+ # See the definition of #pluck in:
10
+ # activerecord/lib/active_record/relation/calculations.rb
11
+ result = klass.connection.select_all(relation.arel, nil, bound_attributes)
9
12
 
10
13
  if result.columns.size != struct_class.members.size
11
14
  raise ArgumentError, 'Expected struct fields and columns lengths to be equal'
@@ -15,7 +18,7 @@ module RelationToStruct::ActiveRecordRelationExtension
15
18
  raise ArgumentError, 'Expected column names to be unique'
16
19
  end
17
20
 
18
- values_after_casting = ActiveRecord::VERSION::MAJOR >= 5 ? result.cast_values() : result.cast_values(klass.column_types)
21
+ values_after_casting = result.cast_values()
19
22
 
20
23
  if result.columns.size == 1
21
24
  values_after_casting.map do |tuple|
@@ -1,3 +1,3 @@
1
1
  module RelationToStruct
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "pry-byebug"
27
27
  spec.add_development_dependency "pg"
28
28
 
29
- spec.add_dependency "activerecord", ">= 4.1", "< 5.2"
30
- spec.add_dependency "activesupport", ">= 4.1", "< 5.2"
29
+ spec.add_dependency "activerecord", ">= 5.0", "< 5.2"
30
+ spec.add_dependency "activesupport", ">= 5.0", "< 5.2"
31
31
  end
@@ -39,6 +39,21 @@ describe ActiveRecord::Relation do
39
39
  ).to eq([test_struct.new(hayek.name, austrian.name)])
40
40
  end
41
41
 
42
+ it 'incorporates both integer and text where bind parameters' do
43
+ hayek = Economist.create!(name: 'F.A. Hayek')
44
+ test_struct = Struct.new(:id, :name)
45
+
46
+ structs = Economist
47
+ .where(
48
+ :id => [hayek.id],
49
+ :name => hayek.name,
50
+ )
51
+ .select(:id, :name)
52
+ .to_structs(test_struct)
53
+
54
+ expect(structs).to eq([test_struct.new(hayek.id, hayek.name)])
55
+ end
56
+
42
57
  it 'properly casts values from arbitrary calculated columns' do
43
58
  hayek = Economist.create!(name: 'F.A. Hayek')
44
59
  scope = Economist.all
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.2.2
4
+ version: 1.3.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: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '4.1'
117
+ version: '5.0'
118
118
  - - "<"
119
119
  - !ruby/object:Gem::Version
120
120
  version: '5.2'
@@ -124,7 +124,7 @@ dependencies:
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: '4.1'
127
+ version: '5.0'
128
128
  - - "<"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '5.2'
@@ -134,7 +134,7 @@ dependencies:
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '4.1'
137
+ version: '5.0'
138
138
  - - "<"
139
139
  - !ruby/object:Gem::Version
140
140
  version: '5.2'
@@ -144,7 +144,7 @@ dependencies:
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: '4.1'
147
+ version: '5.0'
148
148
  - - "<"
149
149
  - !ruby/object:Gem::Version
150
150
  version: '5.2'
@@ -162,14 +162,11 @@ files:
162
162
  - LICENSE.txt
163
163
  - README.md
164
164
  - Rakefile
165
- - gemfiles/rails_4_1.gemfile
166
- - gemfiles/rails_4_2.gemfile
167
165
  - gemfiles/rails_5_0.gemfile
168
166
  - gemfiles/rails_5_1.gemfile
169
167
  - lib/relation_to_struct.rb
170
168
  - lib/relation_to_struct/active_record_base_extension.rb
171
169
  - lib/relation_to_struct/active_record_relation_extension.rb
172
- - lib/relation_to_struct/active_record_result_41_extension.rb
173
170
  - lib/relation_to_struct/version.rb
174
171
  - relation_to_struct.gemspec
175
172
  - spec/active_record_base_spec.rb
@@ -200,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
197
  version: '0'
201
198
  requirements: []
202
199
  rubyforge_project:
203
- rubygems_version: 2.4.5.1
200
+ rubygems_version: 2.6.14
204
201
  signing_key:
205
202
  specification_version: 4
206
203
  summary: Return struct results from ActiveRecord relation queries
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.1.0"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.2.0"
6
-
7
- gemspec path: "../"
@@ -1,26 +0,0 @@
1
- module RelationToStruct::ActiveRecord41ResultExtension
2
- extend ::ActiveSupport::Concern
3
-
4
- included do
5
- alias_method_chain :column_type, :ar_42_semantics
6
- end
7
-
8
- def cast_values(type_overrides = {}) # :nodoc:
9
- types = columns.map { |name| column_type(name, type_overrides) }
10
- result = rows.map do |values|
11
- types.zip(values).map { |type, value| type.type_cast(value) }
12
- end
13
-
14
- columns.one? ? result.map!(&:first) : result
15
- end
16
-
17
- def column_type_with_ar_42_semantics(name, type_overrides = {})
18
- type_overrides.fetch(name) do
19
- column_types.fetch(name, ::ActiveRecord::Result::IDENTITY_TYPE)
20
- end
21
- end
22
- end
23
-
24
- if ActiveRecord.version < Gem::Version.new("4.2.0")
25
- ::ActiveRecord::Result.send(:include, RelationToStruct::ActiveRecord41ResultExtension)
26
- end