Class: JSONAPI::RemoveHasOneAssociationOperation

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

Instance Attribute Summary collapse

Attributes inherited from Operation

#resource_klass

Instance Method Summary collapse

Constructor Details

#initialize(resource_klass, resource_id, association_type) ⇒ RemoveHasOneAssociationOperation

Returns a new instance of RemoveHasOneAssociationOperation.



167
168
169
170
171
# File 'lib/jsonapi/operation.rb', line 167

def initialize(resource_klass, resource_id, association_type)
  @resource_id = resource_id
  @association_type = association_type.to_sym
  super(resource_klass)
end

Instance Attribute Details

#association_typeObject (readonly)

Returns the value of attribute association_type.



165
166
167
# File 'lib/jsonapi/operation.rb', line 165

def association_type
  @association_type
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



165
166
167
# File 'lib/jsonapi/operation.rb', line 165

def resource_id
  @resource_id
end

Instance Method Details

#apply(context) ⇒ Object



173
174
175
176
177
178
# File 'lib/jsonapi/operation.rb', line 173

def apply(context)
  resource = @resource_klass.find_by_key(@resource_id, context: context)
  resource.remove_has_one_link(@association_type)

  return JSONAPI::OperationResult.new(:no_content)
end