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.
114 115 116 117 118 119 |
# File 'lib/jsonapi/operation.rb', line 114 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.
112 113 114 |
# File 'lib/jsonapi/operation.rb', line 112 def association_type @association_type end |
#key_values ⇒ Object (readonly)
Returns the value of attribute key_values.
112 113 114 |
# File 'lib/jsonapi/operation.rb', line 112 def key_values @key_values end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
112 113 114 |
# File 'lib/jsonapi/operation.rb', line 112 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/jsonapi/operation.rb', line 121 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context) @key_values.each do |value| resource.create_has_many_link(@association_type, value) end return JSONAPI::OperationResult.new(:no_content) end |