Sha256: 3243e36d32234f233b6d6f642e67dc1f8e31346cb84b4c5f69f4b4649350ffbc

Contents?: true

Size: 955 Bytes

Versions: 16

Compression:

Stored size: 955 Bytes

Contents

require 'jsonapi/operation_result'

module JSONAPI
  class OperationsProcessor

    def process(request)
      @results = []
      @resources = []

      context = request.context

      transaction {
        request.operations.each do |operation|
          before_operation(context, operation)

          result = operation.apply(context)

          after_operation(context, result)

          @results.push(result)
          if result.has_errors?
            rollback
          end
        end
      }
      @results
    end

    def before_operation(context, operation)
    end

    def after_operation(context, result)
    end

    private

    # The base OperationsProcessor provides no transaction support
    # Override the transaction and rollback methods to provide transaction support.
    # For ActiveRecord transactions you can use the ActiveRecordOperationsProcessor
    def transaction
      yield
    end

    def rollback
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
jsonapi-resources-0.0.16 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.15 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.14 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.13 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.12 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.11 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.10 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.9 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.8 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.7 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.6 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.5 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.4 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.3 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.2 lib/jsonapi/operations_processor.rb
jsonapi-resources-0.0.1 lib/jsonapi/operations_processor.rb