Class: BatchApi::Processor

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

Defined Under Namespace

Modules: Strategies Classes: BadOptionError, NoOperationsError, OperationLimitExceeded

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 BadOptionError if other provided options are invalid. Raises ArgumentError if no operations are provided (nil or []).

Returns the new Processor instance.



27
28
29
30
31
32
33
34
35
# File 'lib/batch_api/processor.rb', line 27

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

  @start_time = Time.now.to_i
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



14
15
16
# File 'lib/batch_api/processor.rb', line 14

def app
  @app
end

#opsObject (readonly)

Returns the value of attribute ops.



14
15
16
# File 'lib/batch_api/processor.rb', line 14

def ops
  @ops
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/batch_api/processor.rb', line 14

def options
  @options
end

Instance Method Details

#execute!Object

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

Returns a set of BatchResponses



47
48
49
# File 'lib/batch_api/processor.rb', line 47

def execute!
  format_response(strategy.execute!(@ops, @options))
end

#strategyObject

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



40
41
42
# File 'lib/batch_api/processor.rb', line 40

def strategy
  BatchApi::Processor::Strategies::Sequential
end