Class: JSONAPI::CreateHasOneAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#key_value ⇒ Object
readonly
Returns the value of attribute key_value.
-
#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_value) ⇒ CreateHasOneAssociationOperation
constructor
A new instance of CreateHasOneAssociationOperation.
Constructor Details
#initialize(resource_klass, resource_id, association_type, key_value) ⇒ CreateHasOneAssociationOperation
Returns a new instance of CreateHasOneAssociationOperation.
76 77 78 79 80 81 |
# File 'lib/jsonapi/operation.rb', line 76 def initialize(resource_klass, resource_id, association_type, key_value) @resource_id = resource_id @key_value = key_value @association_type = association_type.to_sym super(resource_klass) end |
Instance Attribute Details
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
74 75 76 |
# File 'lib/jsonapi/operation.rb', line 74 def association_type @association_type end |
#key_value ⇒ Object (readonly)
Returns the value of attribute key_value.
74 75 76 |
# File 'lib/jsonapi/operation.rb', line 74 def key_value @key_value end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
74 75 76 |
# File 'lib/jsonapi/operation.rb', line 74 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/jsonapi/operation.rb', line 83 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context) resource.create_has_one_link(@association_type, @key_value) resource.save return JSONAPI::OperationResult.new(:no_content) end |