class MGit::System::SystemCommand
Attributes
stderr[R]
stdout[R]
Public Class Methods
new(cmd, opts)
click to toggle source
# File lib/mgit/system.rb, line 10 def initialize(cmd, opts) opts, popen_opts = extract_options(opts) @stdout, @stderr, @st = Open3.capture3(cmd, popen_opts) psystem(stdout.strip) if opts[:print_stdout] return if success? psystem(stderr.strip) if opts[:print_stderr] fail SystemCommandError.new(cmd, opts[:error]) if opts[:raise] end
Public Instance Methods
=~(other)
click to toggle source
# File lib/mgit/system.rb, line 26 def =~(other) (@stdout =~ other) || (@stderr =~ other) end
default_options()
click to toggle source
# File lib/mgit/system.rb, line 30 def default_options { print_stdout: false, print_stderr: false, raise: false, error: 'Command failed.' } end
extract_options(opts)
click to toggle source
# File lib/mgit/system.rb, line 39 def extract_options(opts) popen_opts = opts.dup opts = Hash[ default_options.map do |k, v| [k, popen_opts.key?(k) ? popen_opts.delete(k) : v] end ] [opts, popen_opts] end
success?()
click to toggle source
# File lib/mgit/system.rb, line 22 def success? @st.exitstatus == 0 end