rails_json_serializer 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bd106c9225455d6c867d24cb50b6e06b012aea9f5faeccfab3b8a818756234e
4
- data.tar.gz: 85474e86d17b95e799a8178568cea0969f960ecb846e637133e299945ffea14b
3
+ metadata.gz: dd9c2225a4d011180d3faec0e67fc4969af7aec11c16221fa02f4a5115f83e7a
4
+ data.tar.gz: 942a32755c097539a0a777f958aaba7b053c31f615db0f6bda6ddb41a1ab8fdb
5
5
  SHA512:
6
- metadata.gz: 0d4ea1eaea84942b02b9b756614443b4cb84075b5c598465d220e5831c2628fb1dcacc7191ec3dabaabf33f1380bae1d6bbcb1739f610452581b3c1e6f62b664
7
- data.tar.gz: 9a5130aa48afcc73ee428f72315c24060e3606a75717c22268c4aa3e221169a2373d55eccbe348cfcc4a27fbab43fea769a1eaed210ba3c8248ec2aa438c2396
6
+ metadata.gz: cda83139a44087c474c4b64500586227558b39483e747f6903ed8551f9e92d786641a5ca14c726819291579be6334e6db1800a1a89f5c3c45cdbcd94d2466aa5
7
+ data.tar.gz: 6b809793573a8749e3ac44c0240a0dbda9bcd0ef4cd3e7516ccd30d3952ea76d472689bf7cfcc9ded2dfb15dd37c49c0a59bd980d6be236611484c56138b001b
@@ -1,8 +1,6 @@
1
- require 'active_support/concern'
2
- require 'serializer/application_serializer'
1
+ require_relative 'serializer/model_serializer'
3
2
  Dir[File.join(Rails.root, 'app', 'serializers', '**', '*.rb')].each {|file| require file }
4
- require 'serializer/configuration'
5
- require 'serializer/concern'
3
+ require_relative 'serializer/configuration'
6
4
 
7
5
  module Serializer
8
6
  # config src: http://lizabinante.com/blog/creating-a-configurable-ruby-gem/
@@ -24,4 +22,4 @@ module Serializer
24
22
  end
25
23
 
26
24
  # include the extension
27
- ActiveRecord::Base.send(:include, Serializer::Concern)
25
+ # ActiveRecord::Base.send(:include, Serializer::Concern)
@@ -0,0 +1,188 @@
1
+ module ModelSerializer
2
+ # klazz is that class object that included this module
3
+ def self.included klass
4
+ # START CLASS EVAL
5
+ klass.class_eval do
6
+ if self.const_defined?("#{klass.name}Serializer")
7
+ serializer_klass = "#{klass.name}Serializer".constantize
8
+ serializer_query_names = serializer_klass.public_instance_methods
9
+ if klass.superclass.const_defined?("SERIALIZER_QUERY_KEYS_CACHE")
10
+ self.const_set('SERIALIZER_QUERY_KEYS_CACHE', (serializer_query_names + klass.superclass::SERIALIZER_QUERY_KEYS_CACHE).uniq)
11
+ else
12
+ self.const_set('SERIALIZER_QUERY_KEYS_CACHE', serializer_query_names)
13
+ end
14
+ # Inject class methods, will have access to those queries on the class.
15
+ klass.send(:extend, serializer_klass)
16
+
17
+ # no need to define it if inheriting class has defined it OR has been manually overridden.
18
+ # CLASS METHODS
19
+ klass.send(:define_singleton_method, :serializer) do |opts = {}|
20
+ query = opts[:json_query_override].present? ? self.send(opts[:json_query_override], opts) : serializer_query(opts)
21
+ if Serializer.configuration.enable_includes && query[:include].present? && !opts[:skip_eager_loading]
22
+ includes(generate_includes_from_json_query(query)).as_json(query)
23
+ else
24
+ # Have to use 'all' gets stack level too deep otherwise. Not sure why.
25
+ all.as_json(query)
26
+ end
27
+ end
28
+
29
+ klass.send(:define_singleton_method, :generate_includes_from_json_query) do |options = {}, klass = nil|
30
+ query_filter = {}
31
+ klass = self if klass.nil?
32
+ if options[:include].present? && !options[:skip_eager_loading]
33
+ options[:include].each do |include_key, include_hash|
34
+ next if include_hash[:skip_eager_loading] == true
35
+ # Will 'next' if there is a scope that takes arguments, an instance-dependent scope.
36
+ # Can't eager load when assocation has a instance condition for it's associative scope.
37
+ # Might not be a real assocation
38
+ next if klass.reflect_on_association(include_key).nil?
39
+ next if klass.reflect_on_association(include_key).scope&.arity&.nonzero?
40
+ query_filter[include_key] = {}
41
+ next if include_hash.none?
42
+ query_filter[include_key] = generate_includes_from_json_query(include_hash, klass.reflect_on_association(include_key).klass)
43
+ end
44
+ end
45
+ # Does not include data, just eager-loads. Useful when methods need assocations, but you don't need association data.
46
+ if options[:eager_include].present?
47
+ options[:eager_include].each do |include_key|
48
+ # Will 'next' if there is a scope that takes arguments, an instance-dependent scope.
49
+ # Can't eager load when assocation has a instance condition for it's associative scope.
50
+ # Might not be a real assocation
51
+ next if klass.reflect_on_association(include_key).nil?
52
+ next if klass.reflect_on_association(include_key).scope&.arity&.nonzero?
53
+ query_filter[include_key] ||= {}
54
+ end
55
+ end
56
+ return query_filter
57
+ end
58
+
59
+ klass.send(:define_singleton_method, :as_json_associations_alias_fix) do |options, data, opts = {}|
60
+ if data
61
+ # Depth is almost purely for debugging purposes
62
+ opts[:depth] ||= 0
63
+ if options[:include].present?
64
+ options[:include].each do |include_key, include_hash|
65
+ # The includes doesn't have to have a hash attached. Skip it if it doesn't.
66
+ next if include_hash.nil?
67
+ data_key = include_key.to_s
68
+ if include_hash[:as].present?
69
+ if include_hash[:as].to_s == include_key.to_s
70
+ raise "Serializer: Cannot alias json query association to have the same as the original key; as: #{include_hash[:as].to_s}; original_key: #{include_key.to_s} on self: #{name}"
71
+ end
72
+ alias_name = include_hash[:as]
73
+ data[alias_name.to_s] = data[include_key.to_s]
74
+ data.delete(include_key.to_s)
75
+ data_key = alias_name.to_s
76
+ end
77
+ # At this point, the data could be an array of objects, with no as_json options.
78
+ if !data[data_key].is_a?(Array)
79
+ data[data_key] = as_json_associations_alias_fix(include_hash, data[data_key], {depth: opts[:depth] + 1})
80
+ else
81
+ data[data_key].each_with_index do |value,i|
82
+ data[data_key][i] = as_json_associations_alias_fix(include_hash, value, {depth: opts[:depth] + 1})
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ return data
89
+ end
90
+
91
+ # no need to define it if inheriting class has defined it OR has been manually overridden.
92
+ # INSTANCE Methods
93
+
94
+
95
+ klass.send(:define_method, :as_json) do |options = {}|
96
+ # Not caching records that don't have IDs.
97
+ if !Serializer.configuration.disable_model_caching && self.id && options[:cache_key].present? && !(options.key?(:cache_for) && options[:cache_for].nil?)
98
+ cache_key = "#{self.class.name}_____#{options[:cache_key]}___#{self.id}"
99
+ if Rails.cache.exist?(cache_key)
100
+ Rails.logger.info "Serializer: Cache reading #{cache_key}" if Serializer.configuration.debug
101
+ return Rails.cache.read(cache_key)
102
+ else
103
+ data = super(options)
104
+ data = self.class.as_json_associations_alias_fix(options, data)
105
+ begin
106
+ Rails.logger.info "Serializer: Caching #{cache_key} for #{(options[:cache_for] || Serializer.configuration.default_cache_time)} minutes." if Serializer.configuration.debug
107
+ Rails.cache.write(cache_key, data, expires_in: (options[:cache_for] || Serializer.configuration.default_cache_time).minute)
108
+ rescue Exception => e
109
+ Rails.logger.error "Serializer: Internal Server Error on #{self.class}#as_json ID: #{self.id} for cache key: #{cache_key}"
110
+ Rails.logger.error e.class
111
+ Rails.logger.error e.message
112
+ Rails.logger.error e.backtrace
113
+ end
114
+ return data
115
+ end
116
+ else
117
+ if Serializer.configuration.debug && !Serializer.configuration.disable_model_caching && self.id && options[:cache_key].present? && options.key?(:cache_for) && options[:cache_for].nil?
118
+ Rails.logger.info "Serializer: Caching #{cache_key} NOT caching due to `cache_for: nil`"
119
+ end
120
+ data = super(options)
121
+ data = self.class.as_json_associations_alias_fix(options, data)
122
+ return data
123
+ end
124
+ end
125
+
126
+ if !klass.method_defined?(:serializer)
127
+ klass.send(:define_method, :serializer) do |opts = {}|
128
+ query = opts[:json_query_override].present? ? self.class.send(opts[:json_query_override], opts) : self.class.serializer_query(opts)
129
+ if Serializer.configuration.enable_includes && query[:include].present? && self.class.column_names.include?('id') && self.id.present? && !opts[:skip_eager_loading] && self.respond_to?(:persisted?) && self.persisted?
130
+ # It's an extra SQL call, but most likely worth it to pre-load associations
131
+ self.class.includes(self.class.generate_includes_from_json_query(query)).find(self.id).as_json(query)
132
+ else
133
+ as_json(query)
134
+ end
135
+ end
136
+ end
137
+
138
+ # # SHOULD NOT BE OVERRIDDEN.
139
+ klass.send(:define_method, :clear_serializer_cache) do
140
+ if self.class.const_defined?("SERIALIZER_QUERY_KEYS_CACHE")
141
+ self.class::SERIALIZER_QUERY_KEYS_CACHE.each do |query_name|
142
+ cache_key = "#{self.class.name}_____#{query_name}___#{self.id}"
143
+ Rails.logger.info "Serializer: CLEARING CACHE KEY: #{cache_key}" if Serializer.configuration.debug
144
+ Rails.cache.delete(cache_key)
145
+ end
146
+ return true
147
+ else
148
+ # if Serializer.configuration.debug
149
+ Rails.logger.error(
150
+ """
151
+ ERROR. COULD NOT CLEAR SERIALIZER CACHE FOR: Class #{self.class.name}
152
+ Serializer: Class #{self.class.name} may not have the serializer module #{self.class.name}Serializer defined.
153
+ Nor was it defined on an inheriting class.
154
+ """
155
+ )
156
+ # end
157
+ return nil
158
+ end
159
+ end
160
+
161
+ serializer_query_names.each do |query_name|
162
+ serializer_name = query_name[/(?<name>.+)_query/, :name]
163
+ if serializer_name.nil?
164
+ Rails.logger.error "Serializer: #{serializer_klass.name} method #{query_name} does not end in '(.+)_query', as is expected of serializers" if Serializer.configuration.debug
165
+ next
166
+ end
167
+ if serializer_name == 'serializer'
168
+ # No longer necessary to add here. We've added them above.
169
+ # klass.send(:define_method, serializer_name) do |opts = {}|
170
+ # super({json_query_override: query_name}.merge(opts))
171
+ # end
172
+ # klass.send(:define_singleton_method, serializer_name) do |opts = {}|
173
+ # super({json_query_override: query_name}.merge(opts))
174
+ # end
175
+ else
176
+ klass.send(:define_method, serializer_name) do |opts = {}|
177
+ serializer({json_query_override: query_name}.merge(opts))
178
+ end
179
+ klass.send(:define_singleton_method, serializer_name) do |opts = {}|
180
+ serializer({json_query_override: query_name}.merge(opts))
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+ # END CLASS EVAL
187
+ end
188
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_json_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com
@@ -14,16 +14,100 @@ dependencies:
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: listen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
27
111
  description:
28
112
  email:
29
113
  executables: []
@@ -31,12 +115,11 @@ extensions: []
31
115
  extra_rdoc_files: []
32
116
  files:
33
117
  - lib/serializer.rb
34
- - lib/serializer/application_serializer.rb
35
- - lib/serializer/concern.rb
36
118
  - lib/serializer/configuration.rb
119
+ - lib/serializer/model_serializer.rb
37
120
  homepage: https://github.com/danabr75/rails_json_serializer
38
121
  licenses:
39
- - GNU
122
+ - LGPL-3.0-only
40
123
  metadata: {}
41
124
  post_install_message:
42
125
  rdoc_options: []
@@ -1,10 +0,0 @@
1
- module ApplicationSerializer
2
- def serializer_query opts = {}
3
- {
4
- include: {
5
- },
6
- methods: %w(),
7
- cache_key: __callee__,
8
- }
9
- end
10
- end
@@ -1,183 +0,0 @@
1
- module Serializer
2
- module Concern
3
- # ActiveSupport extend src: https://stackoverflow.com/questions/2328984/rails-extending-activerecordbase
4
- extend ActiveSupport::Concern
5
-
6
- # START MODEL INSTANCE METHODS
7
- def clear_serializer_cache
8
- if self.class.const_defined?("SerializerCacheQueryKeys")
9
- list_of_serializer_query_names = "#{self.class.name}::SerializerCacheQueryKeys".constantize
10
- list_of_serializer_query_names.each do |query_name|
11
- cache_key = "#{self.class.name}_____#{query_name}___#{self.id}"
12
- Rails.logger.info "Serializer: CLEARING CACHE KEY: #{cache_key}" if Serializer.configuration.debug
13
- Rails.cache.delete(cache_key)
14
- end
15
- return true
16
- else
17
- if Serializer.configuration.debug
18
- Rails.logger.info(
19
- """
20
- Serializer: Class #{self.class.name} does not have the serializer module #{self.class.name}Serializer defined.
21
- Nor was it defined on an inheriting class.
22
- """
23
- )
24
- end
25
- return nil
26
- end
27
- end
28
-
29
- def as_json options = {}
30
- # Not caching records that don't have IDs.
31
- if !Serializer.configuration.disable_model_caching && self.id && options[:cache_key].present? && !(options.key?(:cache_for) && options[:cache_for].nil?)
32
- cache_key = "#{self.class.name}_____#{options[:cache_key]}___#{self.id}"
33
- if Rails.cache.exist?(cache_key)
34
- Rails.logger.info "Serializer: Cache reading #{cache_key}" if Serializer.configuration.debug
35
- return Rails.cache.read(cache_key)
36
- else
37
- data = super(options)
38
- data = self.class.as_json_associations_alias_fix(options, data)
39
- begin
40
- Rails.logger.info "Serializer: Caching #{cache_key} for #{(options[:cache_for] || Serializer.configuration.default_cache_time)} minutes." if Serializer.configuration.debug
41
- Rails.cache.write(cache_key, data, expires_in: (options[:cache_for] || Serializer.configuration.default_cache_time).minute)
42
- rescue Exception => e
43
- Rails.logger.error "Serializer: Internal Server Error on #{self.class}#as_json ID: #{self.id} for cache key: #{cache_key}"
44
- Rails.logger.error e.class
45
- Rails.logger.error e.message
46
- Rails.logger.error e.backtrace
47
- end
48
- return data
49
- end
50
- else
51
- if Serializer.configuration.debug && !Serializer.configuration.disable_model_caching && self.id && options[:cache_key].present? && options.key?(:cache_for) && options[:cache_for].nil?
52
- Rails.logger.info "Serializer: Caching #{cache_key} NOT caching due to `cache_for: nil`"
53
- end
54
- data = super(options)
55
- data = self.class.as_json_associations_alias_fix(options, data)
56
- return data
57
- end
58
- end
59
-
60
- # Can override the query, using the options. ex: {json_query_override: :tiny_serializer_query}
61
- def serializer opts = {}
62
- query = opts[:json_query_override].present? ? self.class.send(opts[:json_query_override], opts) : self.class.serializer_query(opts)
63
- if Serializer.configuration.enable_includes && query[:include].present? && self.class.column_names.include?('id') && self.id.present? && !opts[:skip_eager_loading] && self.respond_to?(:persisted?) && self.persisted?
64
- # It's an extra SQL call, but most likely worth it to pre-load associations
65
- self.class.includes(self.class.generate_includes_from_json_query(query)).find(self.id).as_json(query)
66
- else
67
- as_json(query)
68
- end
69
- end
70
- # END MODEL INSTANCE METHODS
71
-
72
- class_methods do
73
- # START MODEL CLASS METHODS
74
- def inherited subclass
75
- if subclass.const_defined?("#{subclass.name}Serializer")
76
- serializer_klass = "#{subclass.name}Serializer".constantize
77
-
78
- if serializer_klass.class == Module
79
- if !serializer_klass.const_defined?("SerializerMethods")
80
- serializer_klass.const_set('SerializerMethods', Module.new {})
81
- end
82
-
83
- serializer_klass.public_instance_methods.each do |query_name|
84
- serializer_name = query_name[/(?<name>.+)_query/, :name]
85
- if serializer_name.nil?
86
- Rails.logger.info "Serializer: #{serializer_klass.name} method #{query_name} does not end in '(.+)_query', as is expected of serializers" if Serializer.configuration.debug
87
- next
88
- end
89
- # Skip if chosen to override it.
90
- next if serializer_klass.respond_to?(serializer_name)
91
- if serializer_name == 'serializer'
92
- serializer_klass::SerializerMethods.send(:define_method, serializer_name) do |opts = {}|
93
- super({json_query_override: query_name}.merge(opts))
94
- end
95
- else
96
- serializer_klass::SerializerMethods.send(:define_method, serializer_name) do |opts = {}|
97
- serializer({json_query_override: query_name}.merge(opts))
98
- end
99
- end
100
- end
101
-
102
- # Inject instance methods
103
- subclass.send(:include, serializer_klass::SerializerMethods)
104
- # Inject class methods
105
- subclass.send(:extend, serializer_klass::SerializerMethods)
106
- # Inject class methods that has queries
107
- subclass.send(:extend, serializer_klass)
108
- # Injecting the Serializer Methods as a namespaced class of the rails class, so we can have
109
- # access to the list of methods to clear their cache.
110
- # 'Class Name + Serializer' does not work with inheritence.
111
- subclass.const_set('SerializerCacheQueryKeys', serializer_klass.public_instance_methods)
112
- else
113
- Rails.logger.info "Serializer: #{serializer_klass.name} was not a Module as expected" if Serializer.configuration.debug
114
- end
115
- end
116
- super(subclass)
117
- end
118
-
119
- # Can override the query, using the options. ex: {json_query_override: :tiny_children_serializer_query}
120
- def serializer opts = {}
121
- query = opts[:json_query_override].present? ? self.send(opts[:json_query_override], opts) : serializer_query(opts)
122
- if Serializer.configuration.enable_includes && query[:include].present? && !opts[:skip_eager_loading]
123
- includes(generate_includes_from_json_query(query)).as_json(query)
124
- else
125
- # Have to use 'all' gets stack level too deep otherwise. Not sure why.
126
- all.as_json(query)
127
- end
128
- end
129
-
130
- def as_json_associations_alias_fix options, data, opts = {}
131
- if data
132
- # Depth is almost purely for debugging purposes
133
- opts[:depth] ||= 0
134
- if options[:include].present?
135
- options[:include].each do |include_key, include_hash|
136
- # The includes doesn't have to have a hash attached. Skip it if it doesn't.
137
- next if include_hash.nil?
138
- data_key = include_key.to_s
139
- if include_hash[:as].present?
140
- if include_hash[:as].to_s == include_key.to_s
141
- raise "Serializer: Cannot alias json query association to have the same as the original key; as: #{include_hash[:as].to_s}; original_key: #{include_key.to_s} on self: #{name}"
142
- end
143
- alias_name = include_hash[:as]
144
- data[alias_name.to_s] = data[include_key.to_s]
145
- data.delete(include_key.to_s)
146
- data_key = alias_name.to_s
147
- end
148
- # At this point, the data could be an array of objects, with no as_json options.
149
- if !data[data_key].is_a?(Array)
150
- data[data_key] = as_json_associations_alias_fix(include_hash, data[data_key], {depth: opts[:depth] + 1})
151
- else
152
- data[data_key].each_with_index do |value,i|
153
- data[data_key][i] = as_json_associations_alias_fix(include_hash, value, {depth: opts[:depth] + 1})
154
- end
155
- end
156
- end
157
- end
158
- end
159
- return data
160
- end
161
-
162
- def generate_includes_from_json_query options = {}, klass = nil
163
- query_filter = {}
164
- klass = self if klass.nil?
165
- if options[:include].present? && !options[:skip_eager_loading]
166
- options[:include].each do |include_key, include_hash|
167
- # Will 'next' if there is a scope that takes arguments, an instance-dependent scope.
168
- # Can't eager load when assocation has a instance condition for it's associative scope.
169
- # Might not be a real assocation
170
- next if klass.reflect_on_association(include_key).nil?
171
- next if klass.reflect_on_association(include_key).scope&.arity&.nonzero?
172
- query_filter[include_key] = {}
173
- next if include_hash.none?
174
- query_filter[include_key] = generate_includes_from_json_query(include_hash, klass.reflect_on_association(include_key).klass)
175
- end
176
- end
177
- return query_filter
178
- end
179
- # END MODEL CLASS METHODS
180
-
181
- end
182
- end
183
- end