Class: JSONAPI::ShowRelatedResourcesOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#paginator ⇒ Object
readonly
Returns the value of attribute paginator.
-
#sort_criteria ⇒ Object
readonly
Returns the value of attribute sort_criteria.
-
#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 = {}) ⇒ ShowRelatedResourcesOperation
constructor
A new instance of ShowRelatedResourcesOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ShowRelatedResourcesOperation
Returns a new instance of ShowRelatedResourcesOperation.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/jsonapi/operation.rb', line 141 def initialize(resource_klass, = {}) @source_klass = .fetch(:source_klass) @source_id = .fetch(:source_id) @association_type = .fetch(:association_type) @filters = [:filters] @sort_criteria = [:sort_criteria] @paginator = [:paginator] @transactional = false super(resource_klass, ) end |
Instance Attribute Details
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def association_type @association_type end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def filters @filters end |
#paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def paginator @paginator end |
#sort_criteria ⇒ Object (readonly)
Returns the value of attribute sort_criteria.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def sort_criteria @sort_criteria end |
#source_id ⇒ Object (readonly)
Returns the value of attribute source_id.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def source_id @source_id end |
#source_klass ⇒ Object (readonly)
Returns the value of attribute source_klass.
139 140 141 |
# File 'lib/jsonapi/operation.rb', line 139 def source_klass @source_klass end |
Instance Method Details
#apply ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/jsonapi/operation.rb', line 152 def apply source_resource = @source_klass.find_by_key(@source_id, context: @context) = source_resource.send(@association_type, { filters: @filters, sort_criteria: @sort_criteria, paginator: @paginator }) return JSONAPI::ResourceOperationResult.new(:ok, ) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |