Class: JSONAPI::ReplacePolymorphicToOneRelationshipOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#key_value ⇒ Object
readonly
Returns the value of attribute key_value.
-
#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 = {}) ⇒ ReplacePolymorphicToOneRelationshipOperation
constructor
A new instance of ReplacePolymorphicToOneRelationshipOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ReplacePolymorphicToOneRelationshipOperation
Returns a new instance of ReplacePolymorphicToOneRelationshipOperation.
270 271 272 273 274 275 276 |
# File 'lib/jsonapi/operation.rb', line 270 def initialize(resource_klass, = {}) super(resource_klass, ) @resource_id = .fetch(:resource_id) @key_value = .fetch(:key_value) @key_type = .fetch(:key_type) @relationship_type = .fetch(:relationship_type).to_sym end |
Instance Attribute Details
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
268 269 270 |
# File 'lib/jsonapi/operation.rb', line 268 def key_type @key_type end |
#key_value ⇒ Object (readonly)
Returns the value of attribute key_value.
268 269 270 |
# File 'lib/jsonapi/operation.rb', line 268 def key_value @key_value end |
#relationship_type ⇒ Object (readonly)
Returns the value of attribute relationship_type.
268 269 270 |
# File 'lib/jsonapi/operation.rb', line 268 def relationship_type @relationship_type end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
268 269 270 |
# File 'lib/jsonapi/operation.rb', line 268 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
278 279 280 281 282 283 |
# File 'lib/jsonapi/operation.rb', line 278 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.replace_polymorphic_to_one_link(@relationship_type, @key_value, @key_type) return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) end |