Class: JSONAPI::RemoveToOneRelationshipOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#relationship_type ⇒ Object
readonly
Returns the value of attribute relationship_type.
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options) ⇒ RemoveToOneRelationshipOperation
constructor
A new instance of RemoveToOneRelationshipOperation.
Constructor Details
#initialize(resource_klass, options) ⇒ RemoveToOneRelationshipOperation
343 344 345 346 347 |
# File 'lib/jsonapi/operation.rb', line 343 def initialize(resource_klass, ) super(resource_klass, ) @resource_id = .fetch(:resource_id) @relationship_type = .fetch(:relationship_type).to_sym end |
Instance Attribute Details
#relationship_type ⇒ Object (readonly)
Returns the value of attribute relationship_type.
341 342 343 |
# File 'lib/jsonapi/operation.rb', line 341 def relationship_type @relationship_type end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
341 342 343 |
# File 'lib/jsonapi/operation.rb', line 341 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
349 350 351 352 353 354 |
# File 'lib/jsonapi/operation.rb', line 349 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 |