Class: Mediakit::Drivers::PopenDriver

Inherits:
Base
  • Object
show all
Defined in:
lib/mediakit/drivers.rb

Direct Known Subclasses

FakeDriver

Instance Attribute Summary

Attributes inherited from Base

#bin

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Mediakit::Drivers::Base

Instance Method Details

#run(args) ⇒ String #run(*args) ⇒ String

return command to execute

Overloads:

  • #run(args) ⇒ String

    Parameters:

    • args (String)

      arguments for command

  • #run(*args) ⇒ String

    Parameters:

    • args (Array)

      arguments for command

Returns:

  • (String)

    command



53
54
55
56
57
# File 'lib/mediakit/drivers.rb', line 53

def command(*args)
  options, rest_args = parse_options(args.dup)
  runner = Mediakit::Process::Runner.new(options)
  runner.build_command(bin, *rest_args)
end

#parse_options(args) ⇒ Object



59
60
61
62
# File 'lib/mediakit/drivers.rb', line 59

def parse_options(args)
  options = (args.last && args.last.kind_of?(Hash)) ? args.pop : {}
  [options, args]
end

#run(args) ⇒ String #run(*args, options) ⇒ String

execute command and return result

Overloads:

  • #run(args) ⇒ String

    Parameters:

    • args (String)

      string argument for command

  • #run(*args, options) ⇒ String

    Parameters:

    • args (Array)

      arguments for command

Returns:

  • (String)

    stdout output



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mediakit/drivers.rb', line 34

def run(*args)
  options, rest_args = parse_options(args.dup)
  runner = Mediakit::Process::Runner.new(options)
  begin
    exit_status, stdout, stderr = runner.run(bin, *rest_args)
    raise(FailError, stdout + stderr) unless exit_status
    stdout
  rescue Mediakit::Process::Runner::CommandNotFoundError => e
    raise(ConfigurationError, "cant' find bin in #{bin}.")
  end
end