Class: JSONAPI::RemoveHasManyAssociationOperation

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

Returns a new instance of RemoveHasManyAssociationOperation.



278
279
280
281
282
283
# File 'lib/jsonapi/operation.rb', line 278

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

Instance Attribute Details

#associated_keyObject (readonly)

Returns the value of attribute associated_key.



276
277
278
# File 'lib/jsonapi/operation.rb', line 276

def associated_key
  @associated_key
end

#association_typeObject (readonly)

Returns the value of attribute association_type.



276
277
278
# File 'lib/jsonapi/operation.rb', line 276

def association_type
  @association_type
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



276
277
278
# File 'lib/jsonapi/operation.rb', line 276

def resource_id
  @resource_id
end

Instance Method Details

#apply(context) ⇒ Object



285
286
287
288
289
290
# File 'lib/jsonapi/operation.rb', line 285

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

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