Class: Cindy::Executor::Base
- Inherits:
-
Object
- Object
- Cindy::Executor::Base
- Defined in:
- lib/cindy/executor/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
Close the eventual underlaying connection.
-
#exec(command, options = {}) ⇒ String, Boolean
Executes the given command.
- #exec!(command, options = {}) ⇒ Object
-
#initialize(logger) ⇒ Base
constructor
X.
Constructor Details
#initialize(logger) ⇒ Base
X
12 13 14 |
# File 'lib/cindy/executor/base.rb', line 12 def initialize(logger) @logger = logger end |
Class Method Details
.from_uri(uri, logger) ⇒ Object
16 17 18 19 20 |
# File 'lib/cindy/executor/base.rb', line 16 def self.from_uri(uri, logger) uri = URI.parse(uri) ObjectSpace.each_object(Class).select { |v| return v.new(uri, logger) if v.ancestors.include?(self) && v.handle?(uri) } raise Exception.new 'Unexpected protocol' end |
Instance Method Details
#close ⇒ Object
Close the eventual underlaying connection
61 62 63 |
# File 'lib/cindy/executor/base.rb', line 61 def close # NOP end |
#exec(command, options = {}) ⇒ String, Boolean
Executes the given command
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cindy/executor/base.rb', line 31 def exec(command, = {}) =begin stdout, stderr, status = exec_imp command, options[:stdin] stdout.chomp! # <logging> if status.zero? if stdout.empty? @logger.info 'Command "%s" executed successfully' % command else @logger.info 'Command "%s" executed successfully (with "%s" returned)' % [ command, stdout ] end else @logger.send(options[:ignore_failure] ? :warn : :error, 'Command "%s" failed with "%s"' % [ command, stderr ]) end # </logging> return status.zero? if options[:check_status_only] raise CommandFailedError.new "Command '#{command}' failed" if !options[:ignore_failure] && 0 != status =end stdout, stderr, status = exec_and_log command, # ?!? stdout end |
#exec!(command, options = {}) ⇒ Object
54 55 56 57 58 |
# File 'lib/cindy/executor/base.rb', line 54 def exec!(command, = {}) stdout, stderr, status = exec_and_log command, raise CommandFailedError.new "Command '#{command}' failed" unless 0 == status stdout end |