Class: JSONAPI::RemoveResourceOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
Attributes inherited from Operation
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options = {}) ⇒ RemoveResourceOperation
constructor
A new instance of RemoveResourceOperation.
Constructor Details
#initialize(resource_klass, options = {}) ⇒ RemoveResourceOperation
Returns a new instance of RemoveResourceOperation.
216 217 218 219 |
# File 'lib/jsonapi/operation.rb', line 216 def initialize(resource_klass, = {}) super(resource_klass, ) @resource_id = .fetch(:resource_id) end |
Instance Attribute Details
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
215 216 217 |
# File 'lib/jsonapi/operation.rb', line 215 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'lib/jsonapi/operation.rb', line 221 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.remove return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) rescue JSONAPI::Exceptions::Error => e return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors) end |