Class: Unixoid::Runner

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

Constant Summary collapse

LOG_FILE =
'logfile.log'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



10
11
12
# File 'lib/unixoid/runner.rb', line 10

def initialize
  @logger = Logger.new(LOG_FILE)
end

Class Method Details

.run(command, opts = {}) ⇒ Object



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

def self.run(command, opts = {})
  new.run(command, opts)
end

Instance Method Details

#log(level, message) ⇒ Object



27
28
29
30
# File 'lib/unixoid/runner.rb', line 27

def log(level, message)
  @logger.send(level, message)
  message
end

#run(command, outcodes: [0]) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/unixoid/runner.rb', line 18

def run(command, outcodes: [0])
  line = Cocaine::CommandLine.new(command, "", expected_outcodes: outcodes, swallow_stderr: true)
  begin
    log(:info, line.run)
  rescue Cocaine::ExitStatusError => error
    log(:error, error.message)
  end
end