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) ⇒ RuntimeCommand::Logger
- #initialize(base_dir = '.') ⇒ RuntimeCommand::Builder constructor
- #puts(message) ⇒ RuntimeCommand::Logger
- #puts_error(message) ⇒ RuntimeCommand::Logger
Constructor Details
#initialize(base_dir = '.') ⇒ RuntimeCommand::Builder
11 12 13 14 15 16 17 |
# File 'lib/runtime_command/builder.rb', line 11 def initialize(base_dir = '.') @base_dir = base_dir @output = true @buffered_log = '' @stdin_prefix = '>' @colors = {} 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) ⇒ RuntimeCommand::Logger
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/runtime_command/builder.rb', line 22 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| stdin.close stdout.each do || logger.stdout() end stderr.each do || logger.stderr() end end rescue Interrupt logger.stderr('Interrupt error') rescue => e logger.stderr(e.to_s) ensure @buffered_log << logger.buffered_log end logger end |
#puts(message) ⇒ RuntimeCommand::Logger
54 55 56 57 58 59 60 |
# File 'lib/runtime_command/builder.rb', line 54 def puts() logger = Logger.new(@output, @colors) logger.stdout() unless .nil? @buffered_log << logger.buffered_log + "\n" logger end |
#puts_error(message) ⇒ RuntimeCommand::Logger
64 65 66 67 68 69 70 |
# File 'lib/runtime_command/builder.rb', line 64 def puts_error() logger = Logger.new(@output, @colors) logger.stderr() unless .nil? @buffered_log << logger.buffered_log + "\n" logger end |