Class: SharkOnLambda::ApiGatewayHandler
- Inherits:
-
Object
- Object
- SharkOnLambda::ApiGatewayHandler
- Defined in:
- lib/shark_on_lambda/api_gateway_handler.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #call(action, event:, context:) ⇒ Object
-
#initialize ⇒ ApiGatewayHandler
constructor
A new instance of ApiGatewayHandler.
Constructor Details
#initialize ⇒ ApiGatewayHandler
Returns a new instance of ApiGatewayHandler.
45 46 47 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 45 def initialize @application = Application.new end |
Class Attribute Details
.controller_class_name ⇒ Object
12 13 14 15 16 17 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 12 def controller_class_name return @controller_class_name if defined?(@controller_class_name) name_inferrer = Inferrers::NameInferrer.from_handler_name(name) @controller_class_name = name_inferrer.controller end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
42 43 44 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 42 def application @application end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
42 43 44 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 42 def env @env end |
Class Method Details
.controller_action?(action) ⇒ Boolean
8 9 10 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 8 def controller_action?(action) controller_actions.include?(action.to_sym) end |
Instance Method Details
#call(action, event:, context:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/shark_on_lambda/api_gateway_handler.rb', line 49 def call(action, event:, context:) raise NoMethodError unless self.class.controller_action?(action) adapter = RackAdapters::ApiGateway.new(context: context, event: event) env = adapter.env env['shark.controller'] = self.class.controller_class_name env['shark.action'] = action.to_s status, headers, body = @application.call(env) adapter.build_response(status, headers, body) end |