Module: Hanami::Lambda::Application Private

Defined in:
lib/hanami/lambda/application.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

The application to configure for AWS Lambda.

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0



13
14
15
16
17
# File 'lib/hanami/lambda/application.rb', line 13

def self.extended(base)
  base.class_eval do
    prepare_load_path if respond_to?(:prepare_load_path)
  end
end

Instance Method Details

#handle_lambda(event:, context:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dispatch event to the handler

Since:

  • 0.1.0



23
24
25
# File 'lib/hanami/lambda/application.rb', line 23

def handle_lambda(event:, context:)
  lambda_dispatcher.call(event: event, context: context)
end

#lambda_dispatcherHanami::Lambda::Dispatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get lambda dispatcher

Returns:

Since:

  • 0.1.0



32
33
34
# File 'lib/hanami/lambda/application.rb', line 32

def lambda_dispatcher
  @lambda_dispatcher ||= load_lambda_dispatcher
end

#load_lambda_dispatcherHanami::Lambda::Dispatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load lambda dispatcher

Returns:

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hanami/lambda/application.rb', line 42

def load_lambda_dispatcher
  if root.directory?
    dispatcher_path = File.join(root, LAMBDA_CONFIG_PATH)

    begin
      require dispatcher_path
    rescue LoadError => exception
      raise exception unless exception.path == dispatcher_path
    end
  end

  begin
    dispatcher_class = namespace.const_get(LAMBDA_CLASS_NAME)
    dispatcher_class.build(
      rack_app: app.rack_app,
      resolver: ->(to) { app.resolve("#{HANDLER_KEY_NAMESPACE}.#{to}") }
    )
  rescue NameError => exception
    raise exception unless exception.name == LAMBDA_CLASS_NAME
  end
end