Class: LambdaConsole::Interact
- Inherits:
-
Object
- Object
- LambdaConsole::Interact
- Defined in:
- lib/lambda-console-ruby/interact.rb
Constant Summary collapse
- DIG =
[NAMESPACE, 'interact']
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(event) ⇒ Interact
constructor
A new instance of Interact.
- #interact ⇒ Object
Constructor Details
#initialize(event) ⇒ Interact
Returns a new instance of Interact.
17 18 19 |
# File 'lib/lambda-console-ruby/interact.rb', line 17 def initialize(event) @event = event end |
Class Method Details
.handle(event) ⇒ Object
11 12 13 |
# File 'lib/lambda-console-ruby/interact.rb', line 11 def handle(event) new(event).interact end |
.handle?(event) ⇒ Boolean
7 8 9 |
# File 'lib/lambda-console-ruby/interact.rb', line 7 def handle?(event) !!event.dig(*DIG) end |
Instance Method Details
#command ⇒ Object
36 37 38 |
# File 'lib/lambda-console-ruby/interact.rb', line 36 def command @event.dig(*DIG) end |
#interact ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lambda-console-ruby/interact.rb', line 21 def interact begin body = eval(command, TOPLEVEL_BINDING).inspect { statusCode: 200, headers: {}, body: body } rescue Exception => e body = "#<#{e.class}:#{e.}>".tap do |b| if e.backtrace b << "\n" b << e.backtrace.join("\n") end end { statusCode: 422, headers: {}, body: body } end end |