Class: JSONAPI::ShowRelatedResourceOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#source_id ⇒ Object
readonly
Returns the value of attribute source_id.
-
#source_klass ⇒ Object
readonly
Returns the value of attribute source_klass.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options = {}) ⇒ ShowRelatedResourceOperation
constructor
A new instance of ShowRelatedResourceOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ShowRelatedResourceOperation
Returns a new instance of ShowRelatedResourceOperation.
118 119 120 121 122 123 124 |
# File 'lib/jsonapi/operation.rb', line 118 def initialize(resource_klass, = {}) @source_klass = .fetch(:source_klass) @source_id = .fetch(:source_id) @association_type = .fetch(:association_type) @transactional = false super(resource_klass, ) end |
Instance Attribute Details
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
116 117 118 |
# File 'lib/jsonapi/operation.rb', line 116 def association_type @association_type end |
#source_id ⇒ Object (readonly)
Returns the value of attribute source_id.
116 117 118 |
# File 'lib/jsonapi/operation.rb', line 116 def source_id @source_id end |
#source_klass ⇒ Object (readonly)
Returns the value of attribute source_klass.
116 117 118 |
# File 'lib/jsonapi/operation.rb', line 116 def source_klass @source_klass end |
Instance Method Details
#apply ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/jsonapi/operation.rb', line 126 def apply source_resource = @source_klass.find_by_key(@source_id, context: @context) = source_resource.send(@association_type) return JSONAPI::ResourceOperationResult.new(:ok, ) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |