Class: BatchApi::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_api/processor.rb,
lib/batch_api/processor/executor.rb,
lib/batch_api/processor/sequential.rb

Defined Under Namespace

Classes: Executor, Sequential

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, app) ⇒ Processor

Public: create a new Processor.

env - a Rack environment hash app - a Rack application

Raises OperationLimitExceeded if more operations are requested than allowed by the BatchApi configuration. Raises Errors::BadOptionError if other provided options are invalid. Raises ArgumentError if no operations are provided (nil or []).

Returns the new Processor instance.



19
20
21
22
23
24
25
# File 'lib/batch_api/processor.rb', line 19

def initialize(request, app)
  @app = app
  @request = request
  @env = request.env
  @ops = self.process_ops
  @options = self.process_options
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/batch_api/processor.rb', line 6

def app
  @app
end

#opsObject (readonly)

Returns the value of attribute ops.



6
7
8
# File 'lib/batch_api/processor.rb', line 6

def ops
  @ops
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/batch_api/processor.rb', line 6

def options
  @options
end

Instance Method Details

#execute!Object

Public: run the batch operations according to the appropriate strategy.

Returns a set of BatchResponses



37
38
39
40
# File 'lib/batch_api/processor.rb', line 37

def execute!
  stack = InternalMiddleware.batch_stack(self)
  format_response(stack.call(middleware_env))
end

#strategyObject

Public: the processing strategy to use, based on the options provided in BatchApi setup and the request. Currently only Sequential is supported.



30
31
32
# File 'lib/batch_api/processor.rb', line 30

def strategy
  BatchApi::Processor::Sequential
end