Class: Autowow::Command

Inherits:
Object
  • Object
show all
Includes:
EasyLogging
Defined in:
lib/autowow/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_thrObject (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

.run(*args) ⇒ Object



8
9
10
# File 'lib/autowow/command.rb', line 8

def self.run(*args)
  Command.new(*args).explain.chronic_execute
end

.run_dry(*args) ⇒ Object



12
13
14
# File 'lib/autowow/command.rb', line 12

def self.run_dry(*args)
  Command.new(*args).execute
end

Instance Method Details

#chronic_executeObject



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

#executeObject



40
41
42
43
# File 'lib/autowow/command.rb', line 40

def execute
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(*@cmd)
  self
end

#explainObject



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

Returns:

  • (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/autowow/command.rb', line 51

def output_matches?(matcher)
  stdout.match(matcher)
end