Class: CodeKindly::Utils::Command
- Inherits:
-
Object
- Object
- CodeKindly::Utils::Command
- Includes:
- Presence
- Defined in:
- lib/code_kindly/utils/command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(command) ⇒ Command
constructor
A new instance of Command.
- #result ⇒ Object
- #run ⇒ Object
Methods included from Presence
blank?, #blank?, present?, #present?
Constructor Details
#initialize(command) ⇒ Command
Returns a new instance of Command.
16 17 18 |
# File 'lib/code_kindly/utils/command.rb', line 16 def initialize(command) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
14 15 16 |
# File 'lib/code_kindly/utils/command.rb', line 14 def command @command end |
Class Method Details
.run(command) ⇒ Object
9 10 11 |
# File 'lib/code_kindly/utils/command.rb', line 9 def run(command) new(command).run end |
Instance Method Details
#result ⇒ Object
28 29 30 31 32 |
# File 'lib/code_kindly/utils/command.rb', line 28 def result return nil if blank? @std_out @std_out.chomp! blank? @std_out ? nil : @std_out end |
#run ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/code_kindly/utils/command.rb', line 20 def run require 'open3' command = @command command.join(' ') if command.is_a?(Array) @std_in, @std_out, @std_err = Open3.capture3(command) self end |