Class: Permpress::Command
- Inherits:
-
Object
- Object
- Permpress::Command
- Defined in:
- lib/permpress/command.rb
Overview
Generic command interface to execute a command with it’s arguments, pipe the output, and exit correctly.
Instance Attribute Summary collapse
-
#executable ⇒ Object
readonly
Returns the value of attribute executable.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #command ⇒ Object (also: #to_s)
-
#initialize(executable, files, options = []) ⇒ Command
constructor
A new instance of Command.
- #run(io = $stdout) ⇒ Object
Constructor Details
#initialize(executable, files, options = []) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 |
# File 'lib/permpress/command.rb', line 9 def initialize(executable, files, = []) @executable = executable @files = files @options = end |
Instance Attribute Details
#executable ⇒ Object (readonly)
Returns the value of attribute executable.
7 8 9 |
# File 'lib/permpress/command.rb', line 7 def executable @executable end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
7 8 9 |
# File 'lib/permpress/command.rb', line 7 def files @files end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/permpress/command.rb', line 7 def @options end |
Instance Method Details
#command ⇒ Object Also known as: to_s
27 28 29 |
# File 'lib/permpress/command.rb', line 27 def command "#{executable} #{flags} #{arguments} 2>&1" end |
#run(io = $stdout) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/permpress/command.rb', line 15 def run(io = $stdout) Bundler.with_clean_env do Open3.popen3(command) do |_, stdout, _, thread| stdout.each do |line| io.puts line end exit thread.value.exitstatus end end end |