Class: Autowow::Command
- Inherits:
-
Object
- Object
- Autowow::Command
- Includes:
- EasyLogging
- Defined in:
- lib/autowow/command.rb
Instance Attribute Summary collapse
-
#wait_thr ⇒ Object
readonly
Returns the value of attribute wait_thr.
Class Method Summary collapse
Instance Method Summary collapse
- #chronic_execute ⇒ Object
- #execute ⇒ Object
- #explain ⇒ Object
-
#initialize(*args) ⇒ Command
constructor
A new instance of Command.
- #output_does_not_match?(matcher) ⇒ Boolean
- #output_matches?(matcher) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Command
Returns a new instance of Command.
31 32 33 |
# File 'lib/autowow/command.rb', line 31 def initialize(*args) @cmd = args end |
Instance Attribute Details
#wait_thr ⇒ Object (readonly)
Returns the value of attribute wait_thr.
29 30 31 |
# File 'lib/autowow/command.rb', line 29 def wait_thr @wait_thr end |
Class Method Details
.popen3_reader(*args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/autowow/command.rb', line 16 def self.popen3_reader(*args) args.each do |arg| reader = <<-EOF def #{arg} @#{arg} = @#{arg}.read.rstrip unless @#{arg}.is_a?(String) return @#{arg} end EOF class_eval(reader) end end |
Instance Method Details
#chronic_execute ⇒ Object
45 46 47 48 49 |
# File 'lib/autowow/command.rb', line 45 def chronic_execute @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd) logger.error(stderr) unless stderr.empty? self end |
#execute ⇒ Object
40 41 42 43 |
# File 'lib/autowow/command.rb', line 40 def execute @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd) self end |
#explain ⇒ Object
35 36 37 38 |
# File 'lib/autowow/command.rb', line 35 def explain logger.debug(@cmd.join(' ')) unless @cmd.empty? self end |
#output_does_not_match?(matcher) ⇒ Boolean
55 56 57 |
# File 'lib/autowow/command.rb', line 55 def output_does_not_match?(matcher) !output_matches?(matcher) end |
#output_matches?(matcher) ⇒ Boolean
51 52 53 |
# File 'lib/autowow/command.rb', line 51 def output_matches?(matcher) stdout.match(matcher) end |