class ServiceOperation::RackMountable

mount in Rails routes.rb with mount(ServiceName => '/path') @todo remove ActionDispatch dependency

Constants

IS_RACK_REQUEST_REGEXP

Public Class Methods

base_call(*args)
Alias for: call
call(*args) click to toggle source

Wrap the call method with a check to see if its a rack request If so merge in request.params and return a rack response

# File lib/service_operation/rack_mountable.rb, line 38
def call(*args)
  if request = rack_request(*args)
    rack_response base_call(request: request)
  else
    base_call(*args)
  end
end
Also aliased as: base_call

Private Class Methods

rack_body(context) click to toggle source
# File lib/service_operation/rack_mountable.rb, line 66
def rack_body(context)
  body = context.body
  body = contextbody.to_json if body.is_a?(Hash)
  body = [body] unless body.is_a?(Array)
  body
end
rack_request(*args) click to toggle source

Request

# File lib/service_operation/rack_mountable.rb, line 52
def rack_request(*args)
  return unless args.first.is_a?(Hash) && args.first.keys.grep(IS_RACK_REQUEST_REGEXP).any?

  ActionDispatch::Request.new(args.first)
end
rack_response(context) click to toggle source

Response

# File lib/service_operation/rack_mountable.rb, line 62
def rack_response(context)
  [context.status, context.headers, rack_body(context)]
end