Class: Rye::Rap

Inherits:
Array
  • Object
show all
Defined in:
lib/rye/rap.rb

Overview

Rye::Rap

This class is a modified Array which is returned by all command methods. The command output is split by line into an instance of this class. If there is only a single element it will act like a String.

This class also contains a reference to the instance of Rye::Box or Rye::Set that the command was executed on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, *args) ⇒ Rap

  • obj an instance of Rye::Box or Rye::Set

  • args anything that can sent to Array#new



31
32
33
34
# File 'lib/rye/rap.rb', line 31

def initialize(obj, *args)
  @obj = obj
  super *args
end

Instance Attribute Details

#cmdObject

The command that was executed.



27
28
29
# File 'lib/rye/rap.rb', line 27

def cmd
  @cmd
end

#exit_codeObject

Returns the value of attribute exit_code.



23
24
25
# File 'lib/rye/rap.rb', line 23

def exit_code
  @exit_code
end

#exit_signalObject

Returns the value of attribute exit_signal.



24
25
26
# File 'lib/rye/rap.rb', line 24

def exit_signal
  @exit_signal
end

#objObject (readonly) Also known as: box, set

A reference to the Rye object instance the command was executed by (Rye::Box or Rye::Set)



19
20
21
# File 'lib/rye/rap.rb', line 19

def obj
  @obj
end

#stderrObject (readonly)

An array containing any STDERR output



22
23
24
# File 'lib/rye/rap.rb', line 22

def stderr
  @stderr
end

Instance Method Details

#add_stderr(*args) ⇒ Object

Add STDERR output from the command executed via SSH.



48
49
50
51
52
53
54
55
# File 'lib/rye/rap.rb', line 48

def add_stderr(*args)
  args = args.flatten.compact
  args = args.first.split($/) if args.size == 1
  @stderr ||= []
  @stderr << args
  @stderr.flatten!
  self
end

#add_stdout(*args) ⇒ Object

Add STDOUT output from the command executed via SSH. This is available to maintain consistency with the add_stderr method. Otherwise there’s no need to use this method (treat the Rye::Rap object like an Array).



61
62
63
64
65
66
# File 'lib/rye/rap.rb', line 61

def add_stdout(*args)
  args = args.flatten.compact
  args = args.first.split($/) if args.size == 1
  self << args
  self.flatten!
end

#grep(*args) ⇒ Object

NOTE: This is broken!



77
78
79
80
81
82
# File 'lib/rye/rap.rb', line 77

def grep *args
  self.select do |boxrap|
    b = boxrap.grep(*args)
    b.empty? ? false : b
  end
end

#stdoutObject

Returns a reference to the Rye::Rap object (which acts like an Array that contains the STDOUT from the command executed over SSH). This is available to maintain consistency with the stderr method.



43
44
45
# File 'lib/rye/rap.rb', line 43

def stdout
  self
end

#to_sObject

Returns the first element if there it’s the only one, otherwise the value of Array#to_s



70
71
72
73
74
# File 'lib/rye/rap.rb', line 70

def to_s
  return self.first if self.size == 1
  return "" if self.size == 0
  super
end