Class: ParallelBatchApi::RackProcessor
- Inherits:
-
Object
- Object
- ParallelBatchApi::RackProcessor
- Defined in:
- lib/parallel_batch_api/rack_processor.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#build ⇒ Object
set value into @env.
-
#initialize(env, options, app) ⇒ RackProcessor
constructor
A new instance of RackProcessor.
- #process ⇒ Object
Constructor Details
#initialize(env, options, app) ⇒ RackProcessor
Returns a new instance of RackProcessor.
8 9 10 11 12 13 14 15 16 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 8 def initialize(env, , app) @method = ['method'] || ParallelBatchApi::HTTP_METHOD_GET @url = ['url'] @params = ['params'] || {} @env = env @headers = ['headers'] || {} @app = app @params = params_for_rails end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def env @env end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def params @params end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 6 def url @url end |
Instance Method Details
#build ⇒ Object
set value into @env
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 30 def build path, qs = url.split('?') headrs = (headers || {}).inject({}) do |heads, (k, v)| heads.tap { |h| h["HTTP_#{k.gsub(/\-/, '_').upcase}"] = v } end env.merge!(headrs) env['REQUEST_METHOD'] = method.upcase if env['REQUEST_URI'] env['REQUEST_URI'] = env['REQUEST_URI'].gsub(/#{ParallelBatchApi.batch_path}.*/, url) end env['REQUEST_PATH'] = env['PATH_INFO'] = path env['ORIGINAL_FULLPATH'] = url env['rack.request.query_string'] = qs env['QUERY_STRING'] = qs env['rack.request.form_hash'] = params env['rack.request.query_hash'] = method == ParallelBatchApi::HTTP_METHOD_GET ? params : nil env['action_dispatch.request.parameters'] = params env['action_dispatch.request.request_parameters'] = params env['CONTENT_TYPE'] = 'text/plain' env['HTTP_CONTENT_TYPE'] = 'text/plain' env['ROW_POST_DATA'] = '' end |
#process ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/parallel_batch_api/rack_processor.rb', line 18 def process build res = begin app.call(env) rescue => er ParallelBatchApi::ErrorResponse.new(er).execute end ParallelBatchApi::Response.new(res, url, params).execute end |