Class: LambdaConsole::Run
- Inherits:
-
Object
- Object
- LambdaConsole::Run
show all
- Defined in:
- lib/lambda-console-ruby/run.rb
Defined Under Namespace
Classes: Error, UnknownCommandPattern
Constant Summary
collapse
- DIG =
[NAMESPACE, 'run']
- PATTERNS =
[%r{.*}]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(event) ⇒ Run
Returns a new instance of Run.
23
24
25
26
|
# File 'lib/lambda-console-ruby/run.rb', line 23
def initialize(event)
@event = event
@body = ''
end
|
Class Method Details
.handle(event) ⇒ Object
17
18
19
|
# File 'lib/lambda-console-ruby/run.rb', line 17
def handle(event)
new(event).run
end
|
.handle?(event) ⇒ Boolean
13
14
15
|
# File 'lib/lambda-console-ruby/run.rb', line 13
def handle?(event)
!!event.dig(*DIG)
end
|
Instance Method Details
#command ⇒ Object
42
43
44
|
# File 'lib/lambda-console-ruby/run.rb', line 42
def command
@event.dig(*DIG)
end
|
#run ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/lambda-console-ruby/run.rb', line 28
def run
validate!
begin
status = Open3.popen3(env, command, chdir: chdir) do |_stdin, stdout, stderr, thread|
@body << stdout.read
@body << stderr.read
thread.value.exitstatus
end
{ statusCode: status, headers: {}, body: @body }
rescue Exception => e
{ statusCode: 1, headers: {}, body: e.message }
end
end
|