Class: JSONAPI::ShowOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#include_directives ⇒ Object
readonly
Returns the value of attribute include_directives.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options = {}) ⇒ ShowOperation
constructor
A new instance of ShowOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ ShowOperation
Returns a new instance of ShowOperation.
72 73 74 75 76 77 |
# File 'lib/jsonapi/operation.rb', line 72 def initialize(resource_klass, = {}) @id = .fetch(:id) @include_directives = [:include_directives] @transactional = false super(resource_klass, ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
70 71 72 |
# File 'lib/jsonapi/operation.rb', line 70 def id @id end |
#include_directives ⇒ Object (readonly)
Returns the value of attribute include_directives.
70 71 72 |
# File 'lib/jsonapi/operation.rb', line 70 def include_directives @include_directives end |
Instance Method Details
#apply ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jsonapi/operation.rb', line 79 def apply key = @resource_klass.verify_key(@id, @context) resource_record = resource_klass.find_by_key(key, context: @context, include_directives: @include_directives) return JSONAPI::ResourceOperationResult.new(:ok, resource_record) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |