Class: JSONAPI::NewOperation

Inherits:
Operation
  • Object
show all
Defined in:
lib/revelry_data/jsonapi_resources_patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_klass, options = {}) ⇒ NewOperation

Returns a new instance of NewOperation.



14
15
16
17
18
# File 'lib/revelry_data/jsonapi_resources_patch.rb', line 14

def initialize(resource_klass, options = {})
  @include_directives = options[:include_directives]
  @transactional = false
  super(resource_klass, options)
end

Instance Attribute Details

#include_directivesObject (readonly)

Returns the value of attribute include_directives.



12
13
14
# File 'lib/revelry_data/jsonapi_resources_patch.rb', line 12

def include_directives
  @include_directives
end

Instance Method Details

#applyObject



20
21
22
23
24
25
26
# File 'lib/revelry_data/jsonapi_resources_patch.rb', line 20

def apply
  resource_record = resource_klass.create(@context)
  return JSONAPI::ResourceOperationResult.new(:ok, resource_record)

rescue JSONAPI::Exceptions::Error => e
  return JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors)
end