Class: JSONAPI::ReplacePolymorphicHasOneAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#key_value ⇒ Object
readonly
Returns the value of attribute key_value.
-
#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 = {}) ⇒ ReplacePolymorphicHasOneAssociationOperation
constructor
A new instance of ReplacePolymorphicHasOneAssociationOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ReplacePolymorphicHasOneAssociationOperation
242 243 244 245 246 247 248 |
# File 'lib/jsonapi/operation.rb', line 242 def initialize(resource_klass, = {}) @resource_id = .fetch(:resource_id) @key_value = .fetch(:key_value) @key_type = .fetch(:key_type) @association_type = .fetch(:association_type).to_sym super(resource_klass, ) end |
Instance Attribute Details
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
240 241 242 |
# File 'lib/jsonapi/operation.rb', line 240 def association_type @association_type end |
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
240 241 242 |
# File 'lib/jsonapi/operation.rb', line 240 def key_type @key_type end |
#key_value ⇒ Object (readonly)
Returns the value of attribute key_value.
240 241 242 |
# File 'lib/jsonapi/operation.rb', line 240 def key_value @key_value end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
240 241 242 |
# File 'lib/jsonapi/operation.rb', line 240 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
250 251 252 253 254 255 |
# File 'lib/jsonapi/operation.rb', line 250 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.replace_polymorphic_has_one_link(@association_type, @key_value, @key_type) return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) end |