Class: JSONAPI::ReplaceHasManyAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#key_values ⇒ Object
readonly
Returns the value of attribute key_values.
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
Attributes inherited from Operation
Instance Method Summary collapse
- #apply(context) ⇒ Object
-
#initialize(resource_klass, resource_id, association_type, key_values) ⇒ ReplaceHasManyAssociationOperation
constructor
A new instance of ReplaceHasManyAssociationOperation.
Constructor Details
#initialize(resource_klass, resource_id, association_type, key_values) ⇒ ReplaceHasManyAssociationOperation
Returns a new instance of ReplaceHasManyAssociationOperation.
128 129 130 131 132 133 |
# File 'lib/jsonapi/operation.rb', line 128 def initialize(resource_klass, resource_id, association_type, key_values) @resource_id = resource_id @key_values = key_values @association_type = association_type.to_sym super(resource_klass) end |
Instance Attribute Details
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
126 127 128 |
# File 'lib/jsonapi/operation.rb', line 126 def association_type @association_type end |
#key_values ⇒ Object (readonly)
Returns the value of attribute key_values.
126 127 128 |
# File 'lib/jsonapi/operation.rb', line 126 def key_values @key_values end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
126 127 128 |
# File 'lib/jsonapi/operation.rb', line 126 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/jsonapi/operation.rb', line 135 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context: context) resource.replace_has_many_links(@association_type, @key_values) return JSONAPI::OperationResult.new(:no_content) end |