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.
134 135 136 137 138 139 |
# File 'lib/jsonapi/operation.rb', line 134 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.
132 133 134 |
# File 'lib/jsonapi/operation.rb', line 132 def association_type @association_type end |
#key_values ⇒ Object (readonly)
Returns the value of attribute key_values.
132 133 134 |
# File 'lib/jsonapi/operation.rb', line 132 def key_values @key_values end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
132 133 134 |
# File 'lib/jsonapi/operation.rb', line 132 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/jsonapi/operation.rb', line 141 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context) resource.replace_has_many_links(@association_type, @key_values) resource.save return JSONAPI::OperationResult.new(:no_content) end |