Class: JSONAPI::ShowAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#parent_key ⇒ Object
readonly
Returns the value of attribute parent_key.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply(context) ⇒ Object
-
#initialize(resource_klass, options = {}) ⇒ ShowAssociationOperation
constructor
A new instance of ShowAssociationOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ShowAssociationOperation
67 68 69 70 71 72 |
# File 'lib/jsonapi/operation.rb', line 67 def initialize(resource_klass, = {}) @parent_key = .fetch(:parent_key) @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.
65 66 67 |
# File 'lib/jsonapi/operation.rb', line 65 def association_type @association_type end |
#parent_key ⇒ Object (readonly)
Returns the value of attribute parent_key.
65 66 67 |
# File 'lib/jsonapi/operation.rb', line 65 def parent_key @parent_key end |
Instance Method Details
#apply(context) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jsonapi/operation.rb', line 74 def apply(context) parent_resource = resource_klass.find_by_key(@parent_key, context: context) return JSONAPI::LinksObjectOperationResult.new(:ok, parent_resource, resource_klass._association(@association_type)) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |