Class: JSONAPI::ReplaceHasManyAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#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) ⇒ ReplaceHasManyAssociationOperation
constructor
A new instance of ReplaceHasManyAssociationOperation.
Constructor Details
#initialize(resource_klass, options) ⇒ ReplaceHasManyAssociationOperation
Returns a new instance of ReplaceHasManyAssociationOperation.
279 280 281 282 283 284 |
# File 'lib/jsonapi/operation.rb', line 279 def initialize(resource_klass, ) @resource_id = .fetch(:resource_id) @data = .fetch(:data) @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.
277 278 279 |
# File 'lib/jsonapi/operation.rb', line 277 def association_type @association_type end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
277 278 279 |
# File 'lib/jsonapi/operation.rb', line 277 def data @data end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
277 278 279 |
# File 'lib/jsonapi/operation.rb', line 277 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
286 287 288 289 290 291 |
# File 'lib/jsonapi/operation.rb', line 286 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.replace_has_many_links(@association_type, @data) return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) end |