Class: BatchRequestApi::Middleware

Inherits:
Object
  • Object
show all
Includes:
BatchParallel, BatchSequential
Defined in:
lib/batch_request_api/middleware.rb

Constant Summary collapse

PATH_INFO_HEADER_KEY =
'PATH_INFO'.freeze

Instance Method Summary collapse

Methods included from BatchSequential

#batch_sequential

Methods included from BatchUtil

#build_response, #get_payload, #setup_env

Methods included from BatchParallel

#batch_parallel

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
# File 'lib/batch_request_api/middleware.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/batch_request_api/middleware.rb', line 16

def call(env)
  if is_batch_sequential_path?(env[PATH_INFO_HEADER_KEY])
    batch_sequential(env)
  elsif is_batch_parallel_path?(env[PATH_INFO_HEADER_KEY])
    batch_parallel(env)
  else
    @app.call(env) # regular RAILS CRUD
  end
end

#is_batch_parallel_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/batch_request_api/middleware.rb', line 30

def is_batch_parallel_path?(path)
  BatchRequestApi.config.batch_parallel_paths.include?(path)
end

#is_batch_sequential_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/batch_request_api/middleware.rb', line 26

def is_batch_sequential_path?(path)
  BatchRequestApi.config.batch_sequential_paths.include?(path)
end