ar-ondemand 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDk0NjYyYTNiZDkzNTRkNzlhNTcxNGY5OTQ3NzlkY2E4MjZhMDczOQ==
5
- data.tar.gz: !binary |-
6
- ZDc5YzJjODZjZDM3Yjk1ODcwZWE1MTZjMzEyZGI4MGM2NWQ2MmJlZQ==
2
+ SHA1:
3
+ metadata.gz: 2c4521729983f1090784fec916b04caaaf25aa21
4
+ data.tar.gz: f7bd9bdd35059b675d80aaf687b8e8e612da4ddf
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTA2NGM0NmM2YWU0MzgyNjI2ZmNkMWQxZGEyYWMwZWY1ODk4ZmJkODljNzM0
10
- MzQ0NTY4ZGI3YjJiZGIyZjA0NTI3ZTRkNmRkMWUxOWQyMzI0OThjNDJhNjQy
11
- ZDk3Y2NmZGRhNzM0ZGFlOTc1NDQzNTJlYzNhYmJiN2Q3OTFhZDc=
12
- data.tar.gz: !binary |-
13
- YWQwZTFlMjU3Yjc3NTNkMzdhODJlMGVjZmVlZTI3ZjE5MDE1NzRlZGY4Y2M2
14
- MTYyN2ZhZWQ2ZjEyNmU3NDIyNDgyMjU1ZjVmYmQwMmQzZjllNDQwZTgxZDJi
15
- YzhhMzExN2NkN2FiZGQ2ZDkwM2I2ZmU1OThkNDBkNGM3ZTZmNDQ=
6
+ metadata.gz: 384adac8921cbbfcbf79145a5371e9424cc2c9e52713d07023f457db4647818d6fb999237c68be3035d93e199b58d41d04d1e9c2e388ba4aee14a4450ca480d6
7
+ data.tar.gz: 8cc4b2d553068f51afeb8712f8f89787a0c4b81c7039e67d2bc695ccdd5aba2110dda633303a19379a0823a2fd1233679848041a08ce10887d4fcbd35d245526
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.3.0
2
+
3
+ * Support for Rails 5+
4
+
1
5
  # 1.1.4
2
6
 
3
7
  ## [misc]
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :test, :development do
9
9
  gem 'sqlite3'
10
10
  end
11
11
 
12
+ gem 'rake'
12
13
  gem 'rspec'
13
14
  gem 'factory_girl'
14
15
  gem 'pry'
data/ar-ondemand.gemspec CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.require_paths = %w(lib)
21
21
 
22
- s.add_dependency 'activesupport', '>= 3.2', '< 5'
23
- s.add_dependency 'activerecord', '>= 3.2', '< 5'
22
+ s.add_dependency 'activesupport', '>= 3.2'
23
+ s.add_dependency 'activerecord', '>= 3.2'
24
+
25
+ s.add_development_dependency 'bundler', '>= 1.14'
26
+ s.add_development_dependency 'rake', '>= 12.0'
24
27
  end
@@ -4,22 +4,26 @@ module ActiveRecord
4
4
 
5
5
  def initialize(model, result_set)
6
6
  @result_set = result_set
7
- @column_models = model.columns.inject({}) {|h,c| h[c.name] = c; h}
7
+ @column_models = model.columns.inject({}) { |h, c| h[c.name] = c; h }
8
8
  result_set.columns.each_with_index do |name, index|
9
9
  column_model = @column_models[name]
10
- self.define_singleton_method(name) {
11
- raise "Not accessible outside of enumeration" if @row.nil?
10
+ self.define_singleton_method(name) do
11
+ raise 'Not accessible outside of enumeration' if @row.nil?
12
12
 
13
- # Rails 4.2 renamed type_cast into type_cast_from_database
14
- # This is not documented in their upgrade docs or release notes.
15
- # See https://github.com/rails/rails/commit/d24e640
16
- # TODO Remove this when dropping support for Rails 3
17
- if column_model.respond_to?(:type_cast)
13
+ if column_model.respond_to?(:type)
14
+ # Rails 5+
15
+ t = column_model.type
16
+ t.is_a?(::Symbol) ? @row[index] : t.cast(@row[index])
17
+ elsif column_model.respond_to?(:type_cast)
18
+ # TODO Remove this when dropping support for Rails 3
18
19
  column_model.type_cast @row[index]
19
20
  else
21
+ # Rails 4.2 renamed type_cast into type_cast_from_database
22
+ # This is not documented in their upgrade docs or release notes.
23
+ # See https://github.com/rails/rails/commit/d24e640
20
24
  column_model.type_cast_from_database @row[index]
21
25
  end
22
- }
26
+ end
23
27
  end
24
28
  end
25
29
 
@@ -46,7 +50,6 @@ module ActiveRecord
46
50
  def size
47
51
  @result_set.rows.size
48
52
  end
49
-
50
53
  end
51
54
  end
52
55
  end
@@ -13,7 +13,6 @@ module ActiveRecord
13
13
 
14
14
  private
15
15
  def query_for_enumeration_reading(ar)
16
-
17
16
  # TODO Clean this up after dropping support for Rails 3
18
17
  if ActiveRecord::VERSION::MAJOR == 3
19
18
  ar = ar.scoped unless ar.respond_to?(:to_sql)
@@ -21,9 +20,10 @@ module ActiveRecord
21
20
  ar = ar.all unless ar.respond_to?(:to_sql)
22
21
  end
23
22
 
24
- ::ActiveRecord::OnDemand::FastEnumeration.new(ar.arel.engine, ::ActiveRecord::Base.connection.exec_query(ar.to_sql))
23
+ model = ar.respond_to?(:model) ? ar.model : ar.arel.engine
24
+ result_set = ::ActiveRecord::Base.connection.exec_query ar.to_sql
25
+ ::ActiveRecord::OnDemand::FastEnumeration.new model, result_set
25
26
  end
26
-
27
27
  end
28
28
  end
29
29
  end
@@ -61,8 +61,9 @@ module ActiveRecord
61
61
  ar = ar.all unless ar.respond_to?(:to_sql)
62
62
  end
63
63
 
64
+ model = ar.respond_to?(:model) ? ar.model : ar.arel.engine
64
65
  results = ::ActiveRecord::Base.connection.exec_query ar.to_sql
65
- ::ActiveRecord::OnDemand::ResultSet.new ar.arel.engine, results, options
66
+ ::ActiveRecord::OnDemand::ResultSet.new model, results, options
66
67
  end
67
68
 
68
69
  def batch_order_for_reading
@@ -75,11 +75,11 @@ module ActiveRecord
75
75
  # replaced with `instantiate` (see http://stackoverflow.com/q/20409650/1935861
76
76
  # and https://github.com/rails/rails/blob/31a95ed/activerecord/lib/active_record/persistence.rb#L56-L70).
77
77
  # TODO Remove when dropping Rails 3 support
78
- if @model_instantiate
79
- rec = @model.instantiate(@record)
80
- else
81
- rec = @model.allocate.init_with('attributes' => @record)
82
- end
78
+ rec = if @model_instantiate
79
+ @model.instantiate(@record)
80
+ else
81
+ @model.allocate.init_with('attributes' => @record)
82
+ end
83
83
  @changes.each_pair do |key, val|
84
84
  next if key == 'id'
85
85
  rec.send("#{key}=".to_sym, val)
@@ -9,6 +9,7 @@ module ActiveRecord
9
9
  @model = model
10
10
  @results = results
11
11
  @column_types = Hash[@model.columns.map { |x| [x.name, x] }]
12
+ determine_type_cast_method
12
13
  @col_indexes = HashWithIndifferentAccess[@results.columns.each_with_index.map { |x, i| [x,i] }]
13
14
  @raw = options.delete :raw
14
15
  @readonly = options.delete :readonly
@@ -56,40 +57,53 @@ module ActiveRecord
56
57
  CACHED_READONLY_CLASSES[attrs] = ::Struct.new(*attrs)
57
58
  end
58
59
 
60
+ def determine_type_cast_method
61
+ _, col = @column_types.first
62
+ return if col.nil?
63
+ @type_cast = if col.respond_to?(:type)
64
+ # Rails 5+
65
+ :type
66
+ elsif col.respond_to?(:type_cast)
67
+ # Rails 3
68
+ :type_cast
69
+ elsif col.respond_to?(:type_cast_from_database)
70
+ # Rails 4.2 renamed type_cast into type_cast_from_database
71
+ # This is not documented in their upgrade docs or release notes.
72
+ # See https://github.com/rails/rails/commit/d24e640
73
+ :type_cast_from_database
74
+ else
75
+ raise 'Unable to determine type cast method for column'
76
+ end
77
+ end
78
+
59
79
  def convert_to_hash(rec)
60
80
  # TODO: Is using HashWithIndifferentAccess[] more efficient?
61
- h = {}
81
+ h = HashWithIndifferentAccess.new
62
82
  @col_indexes.each_pair do |k, v|
63
- if @column_types[k]
64
- # Rails 4.2 renamed type_cast into type_cast_from_database
65
- # This is not documented in their upgrade docs or release notes.
66
- # See https://github.com/rails/rails/commit/d24e640
67
- if @column_types[k].respond_to?(:type_cast)
68
- h[k] = @column_types[k].type_cast rec[v]
69
- else
70
- h[k] = @column_types[k].type_cast_from_database rec[v]
71
- end
72
- else
73
- h[k] = rec[v]
74
- end
83
+ h[k] = cast_value k, rec[v]
75
84
  end
76
- h.with_indifferent_access
85
+ h
77
86
  end
78
87
 
79
88
  def convert_to_struct(klass, rec)
80
89
  vals = []
81
90
  @col_indexes.each_pair do |k, v|
82
- # Rails 4.2 renamed type_cast into type_cast_from_database
83
- # This is not documented in their upgrade docs or release notes.
84
- # See https://github.com/rails/rails/commit/d24e640
85
- if @column_types[k].respond_to?(:type_cast)
86
- vals << @column_types[k].type_cast(rec[v])
87
- else
88
- vals << @column_types[k].type_cast_from_database(rec[v])
89
- end
91
+ vals << cast_value(k, rec[v])
90
92
  end
91
93
  klass.new(*vals)
92
94
  end
95
+
96
+ def cast_value(k, v)
97
+ return v unless @column_types[k]
98
+ if @type_cast == :type
99
+ t = @column_types[k].type
100
+ t.is_a?(::Symbol) ? v : t.cast(v)
101
+ elsif @type_cast == :type_cast
102
+ @column_types[k].type_cast v
103
+ else
104
+ @column_types[k].type_cast_from_database v
105
+ end
106
+ end
93
107
  end
94
108
  end
95
109
  end
@@ -1,3 +1,3 @@
1
1
  module ArOnDemand
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
data/rails_5.1.Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ eval_gemfile 'Gemfile'
2
+
3
+ gem 'activesupport', '~> 5.1.1'
4
+ gem 'activerecord', '~> 5.1.1'
data/solano.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ---
2
- ruby_version: ruby-1.9.3-p392
3
2
  coverage: false
4
3
 
5
4
  rake:
@@ -8,24 +7,37 @@ rake:
8
7
  environment:
9
8
  TZ: UTC
10
9
 
10
+ hooks:
11
+ # Runs after repository is checked out and replaces automatic dependency installation
12
+ package_setup: gem install bundler && bundle install --path=$HOME/bundle --no-deployment
13
+
11
14
  # Build pipelines run concurrently (http://docs.solanolabs.com/Beta/build-pipelines/)
12
15
  pipeline:
13
16
  - rails_3_2
14
17
  - rails_4_0
15
18
  - rails_4_1
16
19
  - rails_4_2
20
+ - rails_5_1
17
21
 
18
22
  # Named profile steps that can be used by build profiles and pipelines
19
23
  profiles:
20
24
  rails_3_2:
25
+ ruby_version: ruby-1.9.3-p392
21
26
  environment:
22
27
  BUNDLE_GEMFILE: rails_3.2.Gemfile
23
28
  rails_4_0:
29
+ ruby_version: ruby-1.9.3-p392
24
30
  environment:
25
31
  BUNDLE_GEMFILE: rails_4.0.Gemfile
26
32
  rails_4_1:
33
+ ruby_version: ruby-1.9.3-p392
27
34
  environment:
28
35
  BUNDLE_GEMFILE: rails_4.1.Gemfile
29
36
  rails_4_2:
37
+ ruby_version: ruby-1.9.3-p392
30
38
  environment:
31
39
  BUNDLE_GEMFILE: rails_4.2.Gemfile
40
+ rails_5_1:
41
+ ruby_version: ruby-2.3.4
42
+ environment:
43
+ BUNDLE_GEMFILE: rails_5.1.Gemfile
metadata CHANGED
@@ -1,55 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-ondemand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '5'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.2'
30
- - - <
31
- - !ruby/object:Gem::Version
32
- version: '5'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activerecord
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ! '>='
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
33
  version: '3.2'
40
- - - <
41
- - !ruby/object:Gem::Version
42
- version: '5'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ! '>='
38
+ - - ">="
48
39
  - !ruby/object:Gem::Version
49
40
  version: '3.2'
50
- - - <
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
51
67
  - !ruby/object:Gem::Version
52
- version: '5'
68
+ version: '12.0'
53
69
  description: Fast access to database results without the memory overhead of ActiveRecord
54
70
  objects
55
71
  email:
@@ -59,7 +75,7 @@ executables: []
59
75
  extensions: []
60
76
  extra_rdoc_files: []
61
77
  files:
62
- - .gitignore
78
+ - ".gitignore"
63
79
  - CHANGELOG.md
64
80
  - CONTRIBUTORS.md
65
81
  - Gemfile
@@ -81,6 +97,7 @@ files:
81
97
  - rails_4.0.Gemfile
82
98
  - rails_4.1.Gemfile
83
99
  - rails_4.2.Gemfile
100
+ - rails_5.1.Gemfile
84
101
  - solano.yml
85
102
  - spec/app/models/audit_record.rb
86
103
  - spec/app/models/widget.rb
@@ -106,17 +123,17 @@ require_paths:
106
123
  - lib
107
124
  required_ruby_version: !ruby/object:Gem::Requirement
108
125
  requirements:
109
- - - ! '>='
126
+ - - ">="
110
127
  - !ruby/object:Gem::Version
111
128
  version: '0'
112
129
  required_rubygems_version: !ruby/object:Gem::Requirement
113
130
  requirements:
114
- - - ! '>='
131
+ - - ">="
115
132
  - !ruby/object:Gem::Version
116
133
  version: '0'
117
134
  requirements: []
118
135
  rubyforge_project:
119
- rubygems_version: 2.4.8
136
+ rubygems_version: 2.5.2
120
137
  signing_key:
121
138
  specification_version: 4
122
139
  summary: ActiveRecord On-demand