Class: JSONAPI::RemoveHasManyAssociationOperation

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

Returns a new instance of RemoveHasManyAssociationOperation.



118
119
120
121
122
123
# File 'lib/jsonapi/operation.rb', line 118

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

Instance Attribute Details

#associated_keyObject (readonly)

Returns the value of attribute associated_key.



116
117
118
# File 'lib/jsonapi/operation.rb', line 116

def associated_key
  @associated_key
end

#association_typeObject (readonly)

Returns the value of attribute association_type.



116
117
118
# File 'lib/jsonapi/operation.rb', line 116

def association_type
  @association_type
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



116
117
118
# File 'lib/jsonapi/operation.rb', line 116

def resource_id
  @resource_id
end

Instance Method Details

#apply(context) ⇒ Object



125
126
127
128
129
130
# File 'lib/jsonapi/operation.rb', line 125

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

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