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{\A\./bin/(rails|rake) db:migrate.*}
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Runner



24
25
26
27
# File 'lib/lamby/runner.rb', line 24

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

Class Method Details

.call(event) ⇒ Object



18
19
20
# File 'lib/lamby/runner.rb', line 18

def call(event)
  new(event).call
end

.handle?(event) ⇒ Boolean



14
15
16
# File 'lib/lamby/runner.rb', line 14

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

Instance Method Details

#callObject



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

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

#commandObject



40
41
42
# File 'lib/lamby/runner.rb', line 40

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