Sha256: 14ba13e3d5f27b28fe12443a7df47404be9f18d727289499607b875fc2b20c9c

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

class ActiveRecordOperationsProcessor < JSONAPI::OperationsProcessor

  private
  def transaction
    if @transactional
      ActiveRecord::Base.transaction do
        yield
      end
    else
      yield
    end
  end

  def rollback
    raise ActiveRecord::Rollback if @transactional
  end

  def process_operation(operation)
    operation.apply(@context)
  rescue ActiveRecord::DeleteRestrictionError => e
    record_locked_error = JSONAPI::Exceptions::RecordLocked.new(e.message)
    return JSONAPI::ErrorsOperationResult.new(record_locked_error.errors[0].code, record_locked_error.errors)

  rescue ActiveRecord::RecordNotFound
    record_not_found = JSONAPI::Exceptions::RecordNotFound.new(operation.associated_key)
    return JSONAPI::ErrorsOperationResult.new(record_not_found.errors[0].code, record_not_found.errors)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsonapi-resources-0.4.1 lib/jsonapi/active_record_operations_processor.rb
jsonapi-resources-0.4.0 lib/jsonapi/active_record_operations_processor.rb