Class: JsonApi::Parameters::Handlers::DefaultHandlers::NilRelationHandler

Inherits:
BaseHandler
  • Object
show all
Includes:
ActiveSupport::Inflector
Defined in:
lib/jsonapi_parameters/default_handlers/nil_relation_handler.rb

Instance Attribute Summary

Attributes inherited from BaseHandler

#included, #relationship_key, #relationship_value

Instance Method Summary collapse

Methods inherited from BaseHandler

call, #find_included_object, #initialize

Constructor Details

This class inherits a constructor from JsonApi::Parameters::Handlers::DefaultHandlers::BaseHandler

Instance Method Details

#handleObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jsonapi_parameters/default_handlers/nil_relation_handler.rb', line 12

def handle
  # Graceful fail if nil on to-many association
  # in case the relationship key is, for instance, `billable_hours`,
  # we have to assume that it is a to-many relationship.
  if pluralize(relationship_key).to_sym == relationship_key
    raise NotImplementedError.new(
      'plural resource cannot be nullified - please create a custom handler for this relation'
    )
  end

  # Handle with empty hash.
  ToOneRelationHandler.new(relationship_key, {}, {}).handle
end