Class: MGit::System::SystemCommand
- Inherits:
-
Object
- Object
- MGit::System::SystemCommand
- Includes:
- Output
- Defined in:
- lib/mgit/system.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #=~(other) ⇒ Object
- #default_options ⇒ Object
- #extract_options(opts) ⇒ Object
-
#initialize(cmd, opts) ⇒ SystemCommand
constructor
A new instance of SystemCommand.
- #success? ⇒ Boolean
Methods included from Output
#perror, #pinfo, #psystem, #ptable, #pwarn
Constructor Details
#initialize(cmd, opts) ⇒ SystemCommand
Returns a new instance of SystemCommand.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mgit/system.rb', line 10 def initialize(cmd, opts) opts, popen_opts = (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 |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
8 9 10 |
# File 'lib/mgit/system.rb', line 8 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
8 9 10 |
# File 'lib/mgit/system.rb', line 8 def stdout @stdout end |
Instance Method Details
#=~(other) ⇒ Object
26 27 28 |
# File 'lib/mgit/system.rb', line 26 def =~(other) (@stdout =~ other) || (@stderr =~ other) end |
#default_options ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mgit/system.rb', line 30 def { print_stdout: false, print_stderr: false, raise: false, error: 'Command failed.' } end |
#extract_options(opts) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mgit/system.rb', line 39 def (opts) popen_opts = opts.dup opts = Hash[ .map do |k, v| [k, popen_opts.key?(k) ? popen_opts.delete(k) : v] end ] [opts, popen_opts] end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/mgit/system.rb', line 22 def success? @st.exitstatus == 0 end |