Class: JSONAPI::ReplaceToManyRelationshipOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#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) ⇒ ReplaceToManyRelationshipOperation
constructor
A new instance of ReplaceToManyRelationshipOperation.
Constructor Details
#initialize(resource_klass, options) ⇒ ReplaceToManyRelationshipOperation
Returns a new instance of ReplaceToManyRelationshipOperation.
307 308 309 310 311 312 |
# File 'lib/jsonapi/operation.rb', line 307 def initialize(resource_klass, ) super(resource_klass, ) @resource_id = .fetch(:resource_id) @data = .fetch(:data) @relationship_type = .fetch(:relationship_type).to_sym end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
305 306 307 |
# File 'lib/jsonapi/operation.rb', line 305 def data @data end |
#relationship_type ⇒ Object (readonly)
Returns the value of attribute relationship_type.
305 306 307 |
# File 'lib/jsonapi/operation.rb', line 305 def relationship_type @relationship_type end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
305 306 307 |
# File 'lib/jsonapi/operation.rb', line 305 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
314 315 316 317 318 319 |
# File 'lib/jsonapi/operation.rb', line 314 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.replace_to_many_links(@relationship_type, @data) return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) end |