Class: RuntimeCommand::Builder
- Inherits:
-
Object
- Object
- RuntimeCommand::Builder
- Defined in:
- lib/runtime_command/builder.rb
Instance Attribute Summary collapse
-
#buffered_log ⇒ Object
readonly
Returns the value of attribute buffered_log.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#output ⇒ Object
Returns the value of attribute output.
-
#stdin_prefix ⇒ Object
Returns the value of attribute stdin_prefix.
Instance Method Summary collapse
- #exec(command, chdir = nil) ⇒ Object
-
#initialize(base_dir = '.') ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(base_dir = '.') ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 |
# File 'lib/runtime_command/builder.rb', line 9 def initialize(base_dir = '.') @base_dir = base_dir @output = true @buffered_log = '' @stdin_prefix = '>' end |
Instance Attribute Details
#buffered_log ⇒ Object (readonly)
Returns the value of attribute buffered_log.
6 7 8 |
# File 'lib/runtime_command/builder.rb', line 6 def buffered_log @buffered_log end |
#colors ⇒ Object
Returns the value of attribute colors.
7 8 9 |
# File 'lib/runtime_command/builder.rb', line 7 def colors @colors end |
#output ⇒ Object
Returns the value of attribute output.
7 8 9 |
# File 'lib/runtime_command/builder.rb', line 7 def output @output end |
#stdin_prefix ⇒ Object
Returns the value of attribute stdin_prefix.
7 8 9 |
# File 'lib/runtime_command/builder.rb', line 7 def stdin_prefix @stdin_prefix end |
Instance Method Details
#exec(command, chdir = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/runtime_command/builder.rb', line 16 def exec(command, chdir = nil) chdir ||= @base_dir logger = Logger.new(@output, @colors) logger.stdin(@stdin_prefix + ' ' + command) begin Open3.popen3(command, chdir: chdir) do |stdin, stdout, stderr, wait_thr| stdin.close stdout.each do |line| logger.stdout(line) end stderr.each do |line| logger.stderr(line) end end @buffered_log << logger.buffered_log rescue => e logger.stderr(e.to_s) @buffered_log << logger.buffered_log end logger end |