Class: JSONAPI::ShowRelationshipOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#parent_key ⇒ Object
readonly
Returns the value of attribute parent_key.
-
#relationship_type ⇒ Object
readonly
Returns the value of attribute relationship_type.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options = {}) ⇒ ShowRelationshipOperation
constructor
A new instance of ShowRelationshipOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ShowRelationshipOperation
96 97 98 99 100 101 |
# File 'lib/jsonapi/operation.rb', line 96 def initialize(resource_klass, = {}) super(resource_klass, ) @parent_key = .fetch(:parent_key) @relationship_type = .fetch(:relationship_type) @transactional = false end |
Instance Attribute Details
#parent_key ⇒ Object (readonly)
Returns the value of attribute parent_key.
94 95 96 |
# File 'lib/jsonapi/operation.rb', line 94 def parent_key @parent_key end |
#relationship_type ⇒ Object (readonly)
Returns the value of attribute relationship_type.
94 95 96 |
# File 'lib/jsonapi/operation.rb', line 94 def relationship_type @relationship_type end |
Instance Method Details
#apply ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/jsonapi/operation.rb', line 103 def apply parent_resource = resource_klass.find_by_key(@parent_key, context: @context) return JSONAPI::LinksObjectOperationResult.new(:ok, parent_resource, resource_klass._relationship(@relationship_type)) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |