class Lamby::Handler

Public Class Methods

call(app, event, context, options = {}) click to toggle source
# File lib/lamby/handler.rb, line 6
def call(app, event, context, options = {})
  new(app, event, context, options).call.response
end
new(app, event, context, options = {}) click to toggle source
# File lib/lamby/handler.rb, line 12
def initialize(app, event, context, options = {})
  @app = app
  @event = event
  @context = context
  @options = options
  @called = false
end

Public Instance Methods

body() click to toggle source
# File lib/lamby/handler.rb, line 34
def body
  @rbody ||= ''.tap do |rbody|
    @body.each { |part| rbody << part }
  end
end
call() click to toggle source
# File lib/lamby/handler.rb, line 40
def call
  return self if @called
  @status, @headers, @body = call_app
  @called = true
  self
end
headers() click to toggle source
# File lib/lamby/handler.rb, line 30
def headers
  @headers
end
response() click to toggle source
# File lib/lamby/handler.rb, line 20
def response
  { statusCode: status,
    headers: headers,
    body: body }.merge(rack_response)
end
status() click to toggle source
# File lib/lamby/handler.rb, line 26
def status
  @status
end

Private Instance Methods

call_app() click to toggle source
# File lib/lamby/handler.rb, line 62
def call_app
  if Debug.on?(@event)
    Debug.call @event, @context, rack.env
  else
    @app.call rack.env
  end
end
rack() click to toggle source
# File lib/lamby/handler.rb, line 49
def rack
  @rack ||= case @options[:rack]
  when :api
    Lamby::RackApi.new @event, @context
  else
    Lamby::RackAlb.new @event, @context
  end
end
rack_response() click to toggle source
# File lib/lamby/handler.rb, line 58
def rack_response
  rack.response(self)
end