Class: JSONAPI::RemoveToManyRelationshipOperation

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) ⇒ RemoveToManyRelationshipOperation

Returns a new instance of RemoveToManyRelationshipOperation.



325
326
327
328
329
330
# File 'lib/jsonapi/operation.rb', line 325

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

Instance Attribute Details

#associated_keyObject (readonly)

Returns the value of attribute associated_key.



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

def associated_key
  @associated_key
end

#relationship_typeObject (readonly)

Returns the value of attribute relationship_type.



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

def relationship_type
  @relationship_type
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



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

def resource_id
  @resource_id
end

Instance Method Details

#applyObject



332
333
334
335
336
337
# File 'lib/jsonapi/operation.rb', line 332

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

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