Class: JSONAPI::RemoveToOneRelationshipOperation

Inherits:
Operation
  • Object
show all
Defined in:
lib/jsonapi/operation.rb

Instance Attribute Summary collapse

Attributes inherited from Operation

#options, #resource_klass, #transactional

Instance Method Summary collapse

Constructor Details

#initialize(resource_klass, options) ⇒ RemoveToOneRelationshipOperation

Returns a new instance of RemoveToOneRelationshipOperation.



315
316
317
318
319
# File 'lib/jsonapi/operation.rb', line 315

def initialize(resource_klass, options)
  super(resource_klass, options)
  @resource_id = options.fetch(:resource_id)
  @relationship_type = options.fetch(:relationship_type).to_sym
end

Instance Attribute Details

#relationship_typeObject (readonly)

Returns the value of attribute relationship_type.



313
314
315
# File 'lib/jsonapi/operation.rb', line 313

def relationship_type
  @relationship_type
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



313
314
315
# File 'lib/jsonapi/operation.rb', line 313

def resource_id
  @resource_id
end

Instance Method Details

#applyObject



321
322
323
324
325
326
# File 'lib/jsonapi/operation.rb', line 321

def apply
  resource = @resource_klass.find_by_key(@resource_id, context: @context)
  result = resource.remove_to_one_link(@relationship_type)

  return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted)
end