Class: Lamby::Runner

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

Defined Under Namespace

Classes: Error, UnknownCommandPattern

Constant Summary collapse

PATTERNS =
[%r{.*}]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Runner

Returns a new instance of Runner.



22
23
24
25
# File 'lib/lamby/runner.rb', line 22

def initialize(event)
  @event = event
  @body = ''
end

Class Method Details

.cmd(event:, context:) ⇒ Object



16
17
18
# File 'lib/lamby/runner.rb', line 16

def cmd(event:, context:)
  new(event).call
end

.handle?(event) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/lamby/runner.rb', line 12

def handle?(event)
  event.dig 'lamby', 'runner'
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/lamby/runner.rb', line 27

def call
  validate!
  status = Open3.popen3(env, command, chdir: chdir) do |_stdin, stdout, stderr, thread|
    @body << stdout.read
    @body << stderr.read
    puts @body
    thread.value.exitstatus
  end
  { statusCode: status, headers: {}, body: @body }
end

#commandObject



38
39
40
# File 'lib/lamby/runner.rb', line 38

def command
  @event.dig 'lamby', 'runner'
end