Class: Lamby::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/lamby/handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, event, context, options = {}) ⇒ Handler

Returns a new instance of Handler.



12
13
14
15
16
17
18
# File 'lib/lamby/handler.rb', line 12

def initialize(app, event, context, options = {})
  @app = app
  @event = event
  @context = context
  @options = options
  @called = false
end

Class Method Details

.call(app, event, context, options = {}) ⇒ Object



6
7
8
# File 'lib/lamby/handler.rb', line 6

def call(app, event, context, options = {})
  new(app, event, context, options).call.response
end

Instance Method Details

#bodyObject



34
35
36
37
38
# File 'lib/lamby/handler.rb', line 34

def body
  @rbody ||= ''.tap do |rbody|
    @body.each { |part| rbody << part }
  end
end

#callObject



40
41
42
43
44
45
# File 'lib/lamby/handler.rb', line 40

def call
  return self if @called
  @status, @headers, @body = call_app
  @called = true
  self
end

#headersObject



30
31
32
# File 'lib/lamby/handler.rb', line 30

def headers
  @headers
end

#responseObject



20
21
22
23
24
# File 'lib/lamby/handler.rb', line 20

def response
  { statusCode: status,
    headers: headers,
    body: body }.merge(rack_response)
end

#statusObject



26
27
28
# File 'lib/lamby/handler.rb', line 26

def status
  @status
end