rails_select_on_includes 0.5.7 → 5.1.4.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
  SHA1:
3
- metadata.gz: 58c0c965a81e2298fa093659f4b8cd490987b7ba
4
- data.tar.gz: 40f53bca05f1f013bd7757702bb378db03bcbd21
3
+ metadata.gz: a469600a55953ed0756cd3c743cb63fe74ee37f3
4
+ data.tar.gz: bb03a46fd331813f085396cf5da81c9a0233e9e9
5
5
  SHA512:
6
- metadata.gz: 4cf96d2b09cafac42251f840afb79f7fcabbb60f6ab7d51642d1a26014cf3563390064e6f77454a70983df04eba1132801a989af3c84a87b0b3527d60af4726f
7
- data.tar.gz: 3b9381419cf0f8d44bc9cc23b8088016863b3c7759cf37fcf04c2ad8f48238b34123ba2314e2f684b0e99f6b3368d78a2d83b92c6d0841975c8b6bdf2a13457a
6
+ metadata.gz: e0e1d39a0dcab674aa7e148406f546f5c5b20b403b8be25f9f53e13d651a29a82594b8c329f15f0de18cbeeafb4110d9af3a4c0f9081e59f8b699b593c0402d5
7
+ data.tar.gz: a812ebc0e9c299de69979ddff256ca89c7e189db8d77c2bcdc8672c65d341dcbc25ad6240923e4d7f507933c7dc4742b4de9cd35275dfa065d57b10c2b035ec8
data/README.md CHANGED
@@ -2,8 +2,11 @@
2
2
  Selected virtual attributes will be now typecasted as usual attributes
3
3
 
4
4
  #Rails version
5
- Supports rails 4.x and rails 5 now!
6
- Maser is now runs on 5.x, rails_4 branch is for rails 4 support
5
+ Supports rails 4.x and rails 5-5.1.4, and 5.1.5 now!
6
+
7
+ Master is now runs on rails 5.1.5,
8
+ rails_5.1.4 branch is for rails less than 5.1.5,
9
+ rails_4 branch is for rails 4 support
7
10
 
8
11
  # RailsSelectOnIncludes
9
12
 
@@ -69,10 +72,13 @@ Add this line to your application's Gemfile:
69
72
 
70
73
  ```ruby
71
74
  #rails 4
72
- gem 'rails_select_on_includes', '~> 0.4.10'
75
+ gem 'rails_select_on_includes', '~> 0.4.11'
76
+
77
+ #rails 5.1.4
78
+ gem 'rails_select_on_includes', '~> 5.1.4.0'
73
79
 
74
- #rails 5
75
- gem 'rails_select_on_includes', '~> 0.5.6'
80
+ #rails 5.1.5
81
+ gem 'rails_select_on_includes', '~> 5.1.5.0'
76
82
  ```
77
83
 
78
84
  And then execute:
@@ -62,80 +62,87 @@ require 'active_support/core_ext/string/filters'
62
62
  end
63
63
  end
64
64
 
65
+ #
65
66
  ::ActiveRecord::Associations::JoinDependency::JoinBase.class_eval do
66
67
  def instantiate(row, aliases, column_types = {}, &block)
67
68
  base_klass.instantiate(extract_record(row, aliases), column_types, &block)
68
69
  end
69
70
  end
70
71
 
72
+
71
73
  ::ActiveRecord::Associations::JoinDependency.class_eval do
72
- def instantiate(result_set, aliases)
73
- primary_key = aliases.column_alias(join_root, join_root.primary_key)
74
+ def instantiate(result_set, &block)
75
+ primary_key = aliases.column_alias(join_root, join_root.primary_key)
74
76
 
75
- seen = Hash.new { |i, object_id|
76
- i[object_id] = Hash.new { |j, child_class|
77
- j[child_class] = {}
77
+ seen = Hash.new { |i, object_id|
78
+ i[object_id] = Hash.new { |j, child_class|
79
+ j[child_class] = {}
80
+ }
78
81
  }
79
- }
80
-
81
- model_cache = Hash.new { |h,klass| h[klass] = {} }
82
- parents = model_cache[join_root]
83
- column_aliases = aliases.column_aliases join_root
84
-
85
- message_bus = ActiveSupport::Notifications.instrumenter
86
-
87
- payload = {
88
- record_count: result_set.length,
89
- class_name: join_root.base_klass.name
90
- }
91
-
92
- message_bus.instrument('instantiation.active_record', payload) do
93
- result_set.each { |row_hash|
94
- parent_key = primary_key ? row_hash[primary_key] : row_hash
95
- # DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
96
- # PREVIOUS > join_root.instantiate(row_hash, column_aliases )
97
- parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
98
- construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
82
+
83
+ model_cache = Hash.new { |h, klass| h[klass] = {} }
84
+ parents = model_cache[join_root]
85
+ column_aliases = aliases.column_aliases join_root
86
+
87
+ message_bus = ActiveSupport::Notifications.instrumenter
88
+
89
+ payload = {
90
+ record_count: result_set.length,
91
+ class_name: join_root.base_klass.name
99
92
  }
100
- end
101
- parents.values
102
- end
103
- end
104
93
 
94
+ message_bus.instrument("instantiation.active_record", payload) do
95
+ result_set.each { |row_hash|
96
+ parent_key = primary_key ? row_hash[primary_key] : row_hash
97
+ # DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ) )
98
+ # PREVIOUS > join_root.instantiate(row_hash, column_aliases )
99
+ # parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, &block)
105
100
 
106
- ::ActiveRecord::FinderMethods.class_eval do
107
- def find_with_associations
108
- # NOTE: the JoinDependency constructed here needs to know about
109
- # any joins already present in `self`, so pass them in
110
- #
111
- # failing to do so means that in cases like activerecord/test/cases/associations/inner_join_association_test.rb:136
112
- # incorrect SQL is generated. In that case, the join dependency for
113
- # SpecialCategorizations is constructed without knowledge of the
114
- # preexisting join in joins_values to categorizations (by way of
115
- # the `has_many :through` for categories).
116
- #
117
- join_dependency = construct_join_dependency(joins_values)
118
-
119
- aliases = join_dependency.aliases
120
- relation = select aliases.columns
121
- relation = apply_join_dependency(relation, join_dependency)
122
-
123
- if block_given?
124
- yield relation
125
- else
126
- if ActiveRecord::NullRelation === relation
127
- []
128
- else
129
- arel = relation.arel
130
- rows = connection.select_all(arel, 'SQL', relation.bound_attributes)
131
- #1 DISTINCTION IS HERE:
132
- # now we gently mokey-patching existing column aliases with select values
133
- aliases.update_aliases_to_select_values(values[:select]) unless values[:select].blank?
134
-
135
- join_dependency.instantiate(rows, aliases)
136
- end
101
+ parent = parents[parent_key] ||=
102
+ join_root.instantiate(row_hash, column_aliases, aliases.slice_selected_attr_types( result_set.column_types ), &block )
103
+ construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
104
+ }
137
105
  end
106
+
107
+ parents.values
138
108
  end
139
109
  end
140
110
 
141
111
 
112
+ ::ActiveRecord::Relation.class_eval do
113
+ private
114
+
115
+ def exec_queries(&block)
116
+ @records =
117
+ if eager_loading?
118
+ find_with_associations do |relation, join_dependency|
119
+ if ActiveRecord::NullRelation === relation
120
+ []
121
+ else
122
+ rows = connection.select_all(relation.arel, "SQL", relation.bound_attributes)
123
+ #1 DISTINCTION IS HERE:
124
+ # now we gently mokey-patching existing column aliases with select values
125
+ join_dependency.aliases.update_aliases_to_select_values(values[:select]) unless values[:select].blank?
126
+
127
+ join_dependency.instantiate(rows, &block)
128
+ end.freeze
129
+ end
130
+ else
131
+ klass.find_by_sql(arel, bound_attributes, &block).freeze
132
+ end
133
+
134
+ preload = preload_values
135
+ preload += includes_values unless eager_loading?
136
+ preloader = nil
137
+ preload.each do |associations|
138
+ preloader ||= build_preloader
139
+ preloader.preload @records, associations
140
+ end
141
+
142
+ @records.each(&:readonly!) if readonly_value
143
+
144
+ @loaded = true
145
+ @records
146
+ end
147
+
148
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsSelectOnIncludes
2
- VERSION = "0.5.7"
2
+ VERSION = "5.1.4.1"
3
3
  end
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "activerecord", ">=5"
33
+ spec.add_dependency "activerecord", '>= 5', '<= 5.1.4'
34
34
 
35
35
  spec.add_development_dependency "rails", ">=5"
36
36
  spec.add_development_dependency "bundler", "~> 1.13"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_select_on_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 5.1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-04 00:00:00.000000000 Z
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.1.4
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.1.4
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rails
29
35
  requirement: !ruby/object:Gem::Requirement