Class: JSONAPI::CreateHasManyAssociationOperation
- 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) ⇒ CreateHasManyAssociationOperation
constructor
A new instance of CreateHasManyAssociationOperation.
Constructor Details
#initialize(resource_klass, resource_id, association_type, key_values) ⇒ CreateHasManyAssociationOperation
Returns a new instance of CreateHasManyAssociationOperation.
110 111 112 113 114 115 |
# File 'lib/jsonapi/operation.rb', line 110 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.
108 109 110 |
# File 'lib/jsonapi/operation.rb', line 108 def association_type @association_type end |
#key_values ⇒ Object (readonly)
Returns the value of attribute key_values.
108 109 110 |
# File 'lib/jsonapi/operation.rb', line 108 def key_values @key_values end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
108 109 110 |
# File 'lib/jsonapi/operation.rb', line 108 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/jsonapi/operation.rb', line 117 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context: context) resource.create_has_many_links(@association_type, @key_values) return JSONAPI::OperationResult.new(:no_content) end |