graphiti 1.0.rc.21 → 1.0.rc.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.standard.yml +14 -0
  4. data/.travis.yml +31 -2
  5. data/Appraisals +16 -10
  6. data/Gemfile +5 -5
  7. data/Guardfile +2 -2
  8. data/README.md +1 -1
  9. data/Rakefile +4 -4
  10. data/exe/graphiti +1 -1
  11. data/gemfiles/rails_4.gemfile +0 -1
  12. data/gemfiles/rails_5.gemfile +0 -1
  13. data/gemfiles/rails_6.gemfile +19 -0
  14. data/graphiti.gemspec +15 -14
  15. data/lib/generators/graphiti/api_test_generator.rb +16 -16
  16. data/lib/generators/graphiti/generator_mixin.rb +7 -7
  17. data/lib/generators/graphiti/install_generator.rb +19 -19
  18. data/lib/generators/graphiti/resource_generator.rb +19 -19
  19. data/lib/generators/graphiti/resource_test_generator.rb +10 -10
  20. data/lib/graphiti.rb +24 -26
  21. data/lib/graphiti/adapters/abstract.rb +25 -39
  22. data/lib/graphiti/adapters/active_record.rb +43 -49
  23. data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +33 -11
  24. data/lib/graphiti/adapters/graphiti_api.rb +16 -16
  25. data/lib/graphiti/adapters/null.rb +0 -12
  26. data/lib/graphiti/cli.rb +7 -7
  27. data/lib/graphiti/configuration.rb +14 -15
  28. data/lib/graphiti/context.rb +1 -1
  29. data/lib/graphiti/debugger.rb +22 -26
  30. data/lib/graphiti/delegates/pagination.rb +9 -9
  31. data/lib/graphiti/deserializer.rb +7 -9
  32. data/lib/graphiti/errors.rb +119 -119
  33. data/lib/graphiti/extensions/boolean_attribute.rb +1 -1
  34. data/lib/graphiti/extensions/extra_attribute.rb +1 -1
  35. data/lib/graphiti/extensions/temp_id.rb +1 -1
  36. data/lib/graphiti/filter_operators.rb +6 -0
  37. data/lib/graphiti/hash_renderer.rb +15 -15
  38. data/lib/graphiti/jsonapi_serializable_ext.rb +1 -1
  39. data/lib/graphiti/query.rb +35 -35
  40. data/lib/graphiti/railtie.rb +14 -10
  41. data/lib/graphiti/renderer.rb +2 -2
  42. data/lib/graphiti/resource.rb +4 -6
  43. data/lib/graphiti/resource/configuration.rb +9 -13
  44. data/lib/graphiti/resource/documentation.rb +4 -2
  45. data/lib/graphiti/resource/dsl.rb +21 -25
  46. data/lib/graphiti/resource/interface.rb +3 -3
  47. data/lib/graphiti/resource/links.rb +14 -14
  48. data/lib/graphiti/resource/persistence.rb +9 -9
  49. data/lib/graphiti/resource/polymorphism.rb +3 -3
  50. data/lib/graphiti/resource/remote.rb +3 -3
  51. data/lib/graphiti/resource/sideloading.rb +5 -5
  52. data/lib/graphiti/resource_proxy.rb +12 -12
  53. data/lib/graphiti/schema.rb +27 -26
  54. data/lib/graphiti/schema_diff.rb +10 -10
  55. data/lib/graphiti/scope.rb +12 -16
  56. data/lib/graphiti/scoping/base.rb +5 -5
  57. data/lib/graphiti/scoping/default_filter.rb +1 -1
  58. data/lib/graphiti/scoping/filter.rb +15 -24
  59. data/lib/graphiti/scoping/filterable.rb +5 -5
  60. data/lib/graphiti/scoping/paginate.rb +1 -1
  61. data/lib/graphiti/scoping/sort.rb +7 -7
  62. data/lib/graphiti/serializer.rb +8 -4
  63. data/lib/graphiti/sideload.rb +23 -39
  64. data/lib/graphiti/sideload/belongs_to.rb +2 -2
  65. data/lib/graphiti/sideload/has_many.rb +1 -1
  66. data/lib/graphiti/sideload/many_to_many.rb +18 -2
  67. data/lib/graphiti/sideload/polymorphic_belongs_to.rb +14 -8
  68. data/lib/graphiti/stats/dsl.rb +7 -1
  69. data/lib/graphiti/tasks.rb +10 -10
  70. data/lib/graphiti/types.rb +98 -98
  71. data/lib/graphiti/util/attribute_check.rb +1 -1
  72. data/lib/graphiti/util/class.rb +3 -3
  73. data/lib/graphiti/util/field_params.rb +1 -1
  74. data/lib/graphiti/util/hash.rb +19 -1
  75. data/lib/graphiti/util/link.rb +15 -19
  76. data/lib/graphiti/util/persistence.rb +17 -22
  77. data/lib/graphiti/util/relationship_payload.rb +2 -2
  78. data/lib/graphiti/util/remote_params.rb +12 -12
  79. data/lib/graphiti/util/remote_serializer.rb +2 -2
  80. data/lib/graphiti/util/serializer_attributes.rb +20 -25
  81. data/lib/graphiti/util/serializer_relationships.rb +17 -18
  82. data/lib/graphiti/util/sideload.rb +1 -1
  83. data/lib/graphiti/util/transaction_hooks_recorder.rb +3 -2
  84. data/lib/graphiti/version.rb +1 -1
  85. metadata +22 -6
@@ -20,7 +20,7 @@ module Graphiti
20
20
  # @param [Hash] options Normal .attribute options
21
21
  def boolean_attribute(name, options = {}, &blk)
22
22
  blk ||= proc { @object.public_send(name) }
23
- field_name = :"is_#{name.to_s.gsub('?', '')}"
23
+ field_name = :"is_#{name.to_s.delete("?")}"
24
24
  attribute field_name, options, &blk
25
25
  end
26
26
  end
@@ -1,4 +1,4 @@
1
- require 'jsonapi/serializable/resource/conditional_fields'
1
+ require "jsonapi/serializable/resource/conditional_fields"
2
2
 
3
3
  module Graphiti
4
4
  module Extensions
@@ -13,7 +13,7 @@ module Graphiti
13
13
  # Common interface for jsonapi-rb extensions
14
14
  def as_jsonapi(*)
15
15
  super.tap do |hash|
16
- if temp_id = @object.instance_variable_get(:'@_jsonapi_temp_id')
16
+ if (temp_id = @object.instance_variable_get(:'@_jsonapi_temp_id'))
17
17
  hash[:'temp-id'] = temp_id
18
18
  end
19
19
  end
@@ -17,9 +17,15 @@ module Graphiti
17
17
  end
18
18
  end
19
19
 
20
+ # rubocop: disable Style/MethodMissingSuper
20
21
  def method_missing(name, *args, &blk)
21
22
  @procs[name] = blk
22
23
  end
24
+ # rubocop: enable Style/MethodMissingSuper
25
+
26
+ def respond_to_missing?(*args)
27
+ true
28
+ end
23
29
 
24
30
  def to_hash
25
31
  @procs
@@ -2,22 +2,22 @@ module Graphiti
2
2
  module SerializableHash
3
3
  def to_hash(fields: nil, include: {})
4
4
  {}.tap do |hash|
5
- _fields = fields[jsonapi_type] if fields
6
- attrs = requested_attributes(_fields).each_with_object({}) do |(k, v), h|
5
+ fields_list = fields[jsonapi_type] if fields
6
+ attrs = requested_attributes(fields_list).each_with_object({}) { |(k, v), h|
7
7
  h[k] = instance_eval(&v)
8
- end
9
- rels = @_relationships.select { |k,v| !!include[k] }
8
+ }
9
+ rels = @_relationships.select { |k, v| !!include[k] }
10
10
  rels.each_with_object({}) do |(k, v), h|
11
11
  serializers = v.send(:resources)
12
12
  attrs[k] = if serializers.is_a?(Array)
13
- serializers.map do |rr| # use private method to avoid array casting
14
- rr.to_hash(fields: fields, include: include[k])
15
- end
16
- elsif serializers.nil?
17
- nil
18
- else
19
- serializers.to_hash(fields: fields, include: include[k])
13
+ serializers.map do |rr| # use private method to avoid array casting
14
+ rr.to_hash(fields: fields, include: include[k])
20
15
  end
16
+ elsif serializers.nil?
17
+ nil
18
+ else
19
+ serializers.to_hash(fields: fields, include: include[k])
20
+ end
21
21
  end
22
22
 
23
23
  hash[:id] = jsonapi_id
@@ -35,7 +35,7 @@ module Graphiti
35
35
  serializers = options[:data]
36
36
  opts = options.slice(:fields, :include)
37
37
  to_hash(serializers, opts).tap do |hash|
38
- hash.merge!(options.slice(:meta)) if !options[:meta].empty?
38
+ hash.merge!(options.slice(:meta)) unless options[:meta].empty?
39
39
  end
40
40
  end
41
41
 
@@ -43,12 +43,12 @@ module Graphiti
43
43
 
44
44
  def to_hash(serializers, opts)
45
45
  {}.tap do |hash|
46
- if serializers.is_a?(Array)
47
- hash[:data] = serializers.map do |s|
46
+ hash[:data] = if serializers.is_a?(Array)
47
+ serializers.map do |s|
48
48
  s.to_hash(opts)
49
49
  end
50
50
  else
51
- hash[:data] = serializers.to_hash(opts)
51
+ serializers.to_hash(opts)
52
52
  end
53
53
  end
54
54
  end
@@ -6,7 +6,7 @@ module Graphiti
6
6
  # Instead, this variable is assigned when the query is resolved
7
7
  # To ensure we always render with the *resource* serializer
8
8
  module RendererOverrides
9
- def _build(object, exposures, klass)
9
+ def _build(object, exposures, _klass)
10
10
  resource = object.instance_variable_get(:@__graphiti_resource)
11
11
  klass = object.instance_variable_get(:@__graphiti_serializer)
12
12
  klass.new(exposures.merge(object: object, resource: resource))
@@ -1,6 +1,6 @@
1
1
  module Graphiti
2
2
  class Query
3
- attr_reader :resource, :include_hash, :association_name, :params
3
+ attr_reader :resource, :association_name, :params
4
4
 
5
5
  def initialize(resource, params, association_name = nil, nested_include = nil, parents = [])
6
6
  @resource = resource
@@ -18,13 +18,13 @@ module Graphiti
18
18
  end
19
19
 
20
20
  def top_level?
21
- not association?
21
+ !association?
22
22
  end
23
23
 
24
24
  def links?
25
- return false if [:json, :xml, 'json', 'xml'].include?(params[:format])
25
+ return false if [:json, :xml, "json", "xml"].include?(params[:format])
26
26
  if Graphiti.config.links_on_demand
27
- [true, 'true'].include?(@params[:links])
27
+ [true, "true"].include?(@params[:links])
28
28
  else
29
29
  true
30
30
  end
@@ -32,7 +32,7 @@ module Graphiti
32
32
 
33
33
  def pagination_links?
34
34
  if Graphiti.config.pagination_links_on_demand
35
- [true, 'true'].include?(@params[:pagination_links])
35
+ [true, "true"].include?(@params[:pagination_links])
36
36
  else
37
37
  Graphiti.config.pagination_links
38
38
  end
@@ -74,9 +74,9 @@ module Graphiti
74
74
 
75
75
  def resource_for_sideload(sideload)
76
76
  if @resource.remote?
77
- Class.new(Graphiti::Resource) do
78
- self.remote = '_remote_sideload_'
79
- end.new
77
+ Class.new(Graphiti::Resource) {
78
+ self.remote = "_remote_sideload_"
79
+ }.new
80
80
  else
81
81
  sideload.resource
82
82
  end
@@ -90,9 +90,9 @@ module Graphiti
90
90
 
91
91
  if sideload || @resource.remote?
92
92
  sl_resource = resource_for_sideload(sideload)
93
- _parents = parents + [self]
94
- sub_hash = sub_hash[:include] if sub_hash.has_key?(:include)
95
- hash[key] = Query.new(sl_resource, @params, key, sub_hash, _parents)
93
+ query_parents = parents + [self]
94
+ sub_hash = sub_hash[:include] if sub_hash.key?(:include)
95
+ hash[key] = Query.new(sl_resource, @params, key, sub_hash, query_parents)
96
96
  else
97
97
  handle_missing_sideload(key)
98
98
  end
@@ -132,7 +132,7 @@ module Graphiti
132
132
  hash[filter_name] = filter_value
133
133
  end
134
134
  elsif nested?(name)
135
- name = name.to_s.split('.').last.to_sym
135
+ name = name.to_s.split(".").last.to_sym
136
136
  validate!(name, :filterable)
137
137
  hash[name] = value
138
138
  elsif top_level? && validate!(name, :filterable)
@@ -154,11 +154,11 @@ module Graphiti
154
154
  unless @resource.remote?
155
155
  @resource.get_attr!(key, :sortable, request: true)
156
156
  end
157
- arr << { key => value }
157
+ arr << {key => value}
158
158
  elsif !type && top_level? && validate!(key, :sortable)
159
- arr << { key => value }
159
+ arr << {key => value}
160
160
  elsif nested?("#{type}.#{key}")
161
- arr << { key => value }
161
+ arr << {key => value}
162
162
  end
163
163
  end
164
164
  end
@@ -170,11 +170,11 @@ module Graphiti
170
170
  {}.tap do |hash|
171
171
  (@params[:page] || {}).each_pair do |name, value|
172
172
  if legacy_nested?(name)
173
- value.each_pair do |k,v|
173
+ value.each_pair do |k, v|
174
174
  hash[k.to_sym] = v.to_i
175
175
  end
176
176
  elsif nested?(name)
177
- hash[name.to_s.split('.').last.to_sym] = value
177
+ hash[name.to_s.split(".").last.to_sym] = value
178
178
  elsif top_level? && [:number, :size].include?(name.to_sym)
179
179
  hash[name.to_sym] = value.to_i
180
180
  end
@@ -188,7 +188,7 @@ module Graphiti
188
188
  requested = include_directive.to_hash
189
189
 
190
190
  allowlist = nil
191
- if @resource.context && @resource.context.respond_to?(:sideload_allowlist)
191
+ if @resource.context&.respond_to?(:sideload_allowlist)
192
192
  allowlist = @resource.context.sideload_allowlist
193
193
  allowlist = allowlist[@resource.context_namespace] if allowlist
194
194
  end
@@ -204,9 +204,9 @@ module Graphiti
204
204
  {}.tap do |hash|
205
205
  (@params[:stats] || {}).each_pair do |k, v|
206
206
  if legacy_nested?(k)
207
- raise NotImplementedError.new('Association statistics are not currently supported')
207
+ raise NotImplementedError.new("Association statistics are not currently supported")
208
208
  elsif top_level?
209
- v = v.split(',') if v.is_a?(String)
209
+ v = v.split(",") if v.is_a?(String)
210
210
  hash[k.to_sym] = Array(v).flatten.map(&:to_sym)
211
211
  end
212
212
  end
@@ -215,7 +215,7 @@ module Graphiti
215
215
  end
216
216
 
217
217
  def paginate?
218
- not [false, 'false'].include?(@params[:paginate])
218
+ ![false, "false"].include?(@params[:paginate])
219
219
  end
220
220
 
221
221
  private
@@ -225,10 +225,10 @@ module Graphiti
225
225
  # resource names/types
226
226
  # TODO: Eventually, remove the legacy logic
227
227
  def validate!(name, flag)
228
- return false if name.to_s.include?('.') # nested
228
+ return false if name.to_s.include?(".") # nested
229
229
  return true if @resource.remote?
230
230
 
231
- if att = @resource.get_attr(name, flag, request: true)
231
+ if (att = @resource.get_attr(name, flag, request: true))
232
232
  return att
233
233
  else
234
234
  not_associated_name = !@resource.class.association_names.include?(name)
@@ -245,8 +245,8 @@ module Graphiti
245
245
  def nested?(name)
246
246
  return false unless association?
247
247
 
248
- split = name.to_s.split('.')
249
- query_names = split[0..split.length-2].map(&:to_sym)
248
+ split = name.to_s.split(".")
249
+ query_names = split[0..split.length - 2].map(&:to_sym)
250
250
  my_names = parents.map(&:association_name).compact + [association_name].compact
251
251
  query_names == my_names
252
252
  end
@@ -260,7 +260,7 @@ module Graphiti
260
260
  {}.tap do |hash|
261
261
  fieldset.each_pair do |type, fields|
262
262
  type = type.to_sym
263
- fields = fields.split(',') unless fields.is_a?(Array)
263
+ fields = fields.split(",") unless fields.is_a?(Array)
264
264
  hash[type] = fields.map(&:to_sym)
265
265
  end
266
266
  end
@@ -278,21 +278,21 @@ module Graphiti
278
278
  end
279
279
 
280
280
  def sort_hash(attr)
281
- value = attr[0] == '-' ? :desc : :asc
282
- key = attr.sub('-', '').to_sym
281
+ value = attr[0] == "-" ? :desc : :asc
282
+ key = attr.sub("-", "").to_sym
283
283
 
284
- { key => value }
284
+ {key => value}
285
285
  end
286
286
 
287
287
  def sort_hashes
288
- sorts = @params[:sort].split(',')
288
+ sorts = @params[:sort].split(",")
289
289
  sorts.each do |s|
290
290
  attr = nil
291
291
  type = s
292
- if s.include?('.')
293
- split = s.split('.')
292
+ if s.include?(".")
293
+ split = s.split(".")
294
294
  attr = split.pop
295
- type = split.join('.')
295
+ type = split.join(".")
296
296
  end
297
297
 
298
298
  if attr.nil? # top-level
@@ -300,8 +300,8 @@ module Graphiti
300
300
  hash = sort_hash(type)
301
301
  yield hash.keys.first.to_sym, hash.values.first
302
302
  else
303
- if type[0] == '-'
304
- type = type.sub('-', '')
303
+ if type[0] == "-"
304
+ type = type.sub("-", "")
305
305
  attr = "-#{attr}"
306
306
  end
307
307
  hash = sort_hash(attr)
@@ -8,18 +8,18 @@ module Graphiti
8
8
  initializer "graphiti.require_activerecord_adapter" do
9
9
  config.after_initialize do |app|
10
10
  ActiveSupport.on_load(:active_record) do
11
- require 'graphiti/adapters/active_record'
11
+ require "graphiti/adapters/active_record"
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
- initializer 'graphti.logger' do
16
+ initializer "graphti.logger" do
17
17
  config.after_initialize do
18
18
  Graphiti.logger = ::Rails.logger
19
19
  end
20
20
  end
21
21
 
22
- initializer 'graphiti.init' do
22
+ initializer "graphiti.init" do
23
23
  if ::Rails.application.config.eager_load
24
24
  config.after_initialize do |app|
25
25
  ::Rails.application.reload_routes!
@@ -28,7 +28,7 @@ module Graphiti
28
28
  end
29
29
 
30
30
  if Mime[:jsonapi].nil? # rails 4
31
- Mime::Type.register('application/vnd.api+json', :jsonapi)
31
+ Mime::Type.register("application/vnd.api+json", :jsonapi)
32
32
  end
33
33
  register_parameter_parser
34
34
  register_renderers
@@ -56,10 +56,10 @@ module Graphiti
56
56
  ::ActionController::Renderers.add(:jsonapi) do |proxy, options|
57
57
  self.content_type ||= Mime[:jsonapi]
58
58
 
59
- opts = {}
60
- if respond_to?(:default_jsonapi_render_options)
61
- opts = default_jsonapi_render_options
62
- end
59
+ # opts = {}
60
+ # if respond_to?(:default_jsonapi_render_options)
61
+ # opts = default_jsonapi_render_options
62
+ # end
63
63
 
64
64
  if proxy.is_a?(Hash) # for destroy
65
65
  render(options.merge(json: proxy))
@@ -77,7 +77,7 @@ module Graphiti
77
77
  proxy.data, proxy.payload.relationships
78
78
 
79
79
  render \
80
- json: { errors: validation.errors },
80
+ json: {errors: validation.errors},
81
81
  status: :unprocessable_entity
82
82
  end
83
83
  end
@@ -103,7 +103,11 @@ module Graphiti
103
103
  method = :DELETE
104
104
  end
105
105
 
106
- route = ::Rails.application.routes.recognize_path(path, method: method) rescue nil
106
+ route = begin
107
+ ::Rails.application.routes.recognize_path(path, method: method)
108
+ rescue
109
+ nil
110
+ end
107
111
  "#{route[:controller]}_controller".classify.safe_constantize if route
108
112
  }
109
113
  end
@@ -1,6 +1,6 @@
1
1
  module Graphiti
2
2
  class Renderer
3
- CONTENT_TYPE = 'application/vnd.api+json'
3
+ CONTENT_TYPE = "application/vnd.api+json"
4
4
 
5
5
  attr_reader :proxy, :options
6
6
 
@@ -46,7 +46,7 @@ module Graphiti
46
46
  options[:include] = proxy.include_hash
47
47
  options[:links] = proxy.pagination.links if proxy.pagination.links?
48
48
  options[:meta] ||= {}
49
- options[:meta].merge!(stats: proxy.stats) unless proxy.stats.empty?
49
+ options[:meta][:stats] = proxy.stats unless proxy.stats.empty?
50
50
  options[:meta][:debug] = Debugger.to_a if debug_json?
51
51
 
52
52
  renderer.render(records, options)
@@ -8,13 +8,11 @@ module Graphiti
8
8
  include Documentation
9
9
  include Persistence
10
10
 
11
- attr_reader :context
12
-
13
11
  def around_scoping(scope, query_hash)
14
12
  extra_fields = query_hash[:extra_fields] || {}
15
13
  extra_fields = extra_fields[type] || []
16
14
  extra_fields.each do |name|
17
- if config = self.class.config[:extra_attributes][name]
15
+ if (config = self.class.config[:extra_attributes][name])
18
16
  scope = instance_exec(scope, &config[:hook]) if config[:hook]
19
17
  end
20
18
  end
@@ -71,13 +69,13 @@ module Graphiti
71
69
  type_name = filters[name][:type]
72
70
  end
73
71
  type = Graphiti::Types[type_name]
74
- return if value.nil? && type[:kind] != 'array'
72
+ return if value.nil? && type[:kind] != "array"
75
73
  begin
76
74
  flag = :read if flag == :readable
77
75
  flag = :write if flag == :writable
78
76
  flag = :params if [:sortable, :filterable].include?(flag)
79
77
  type[flag][value]
80
- rescue Exception => e
78
+ rescue => e
81
79
  raise Errors::TypecastFailed.new(self, name, value, e)
82
80
  end
83
81
  end
@@ -135,7 +133,7 @@ module Graphiti
135
133
  response = yield
136
134
  end
137
135
  rescue Errors::ValidationError => e
138
- response = { result: e.validation_response }
136
+ response = {result: e.validation_response}
139
137
  end
140
138
  response
141
139
  end
@@ -23,8 +23,8 @@ module Graphiti
23
23
  end
24
24
 
25
25
  def type=(val)
26
- if val = super
27
- self.serializer.type(val)
26
+ if (val = super)
27
+ serializer.type(val)
28
28
  end
29
29
  end
30
30
 
@@ -43,7 +43,7 @@ module Graphiti
43
43
  def model
44
44
  klass = super
45
45
  unless klass || abstract_class?
46
- if klass = infer_model
46
+ if (klass = infer_model)
47
47
  self.model = klass
48
48
  else
49
49
  raise Errors::ModelNotFound.new(self)
@@ -86,11 +86,7 @@ module Graphiti
86
86
  klass.adapter ||= Adapters::Abstract
87
87
  klass.max_page_size ||= DEFAULT_MAX_PAGE_SIZE
88
88
  # re-assigning causes a new Class.new
89
- if klass.serializer
90
- klass.serializer = klass.serializer
91
- else
92
- klass.serializer = klass.infer_serializer_superclass
93
- end
89
+ klass.serializer = (klass.serializer || klass.infer_serializer_superclass)
94
90
  klass.type ||= klass.infer_type
95
91
  default(klass, :attributes_readable_by_default, true)
96
92
  default(klass, :attributes_writable_by_default, true)
@@ -114,7 +110,7 @@ module Graphiti
114
110
  end
115
111
 
116
112
  def get_attr(name, flag, opts = {})
117
- defaults = { request: false }
113
+ defaults = {request: false}
118
114
  opts = defaults.merge(opts)
119
115
  new.get_attr(name, flag, opts)
120
116
  end
@@ -128,7 +124,7 @@ module Graphiti
128
124
  end
129
125
 
130
126
  def abstract_class=(val)
131
- if @abstract_class = val
127
+ if (@abstract_class = val)
132
128
  self.serializer = nil
133
129
  self.type = nil
134
130
  end
@@ -136,14 +132,14 @@ module Graphiti
136
132
 
137
133
  def infer_type
138
134
  if name.present?
139
- name.demodulize.gsub('Resource','').underscore.pluralize.to_sym
135
+ name.demodulize.gsub("Resource", "").underscore.pluralize.to_sym
140
136
  else
141
137
  :undefined_jsonapi_type
142
138
  end
143
139
  end
144
140
 
145
141
  def infer_model
146
- name.gsub('Resource', '').safe_constantize if name
142
+ name&.gsub("Resource", "")&.safe_constantize
147
143
  end
148
144
 
149
145
  # @api private
@@ -185,7 +181,7 @@ module Graphiti
185
181
  attributes: {},
186
182
  extra_attributes: {},
187
183
  sideloads: {},
188
- callbacks: {}
184
+ callbacks: {},
189
185
  }
190
186
  end
191
187