### Home Classes Methods

### In Files

- lib/rye/rap.rb

### Parent

Array

### Methods

- ::new
- #>
- #>>
- #add_exit_status
- #add_stderr
- #add_stdout
- #code
- #inspect
- #stdout
- #to_s

### Files

- LICENSE.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Rye
- Rye::Box
- Rye::Box::InstanceExecHelper
- Rye::Cmd
- Rye::CommandNotFound
- Rye::Err
- Rye::Hop
- Rye::Key
- Rye::Key::BadFile
- Rye::Key::BadPerm
- Rye::NoBoxes
- Rye::NoHost
- Rye::NoPassword
- Rye::NoPty
- Rye::NotConnected
- Rye::Rap
- Rye::RyeError
- Rye::Set
- Rye::Tpl
- Rye::VERSION
- Object

No matching classes.

# Rye::Rap

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.

### Attributes

box[R]

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

cmd[RW]

The command that was executed.

exit_signal[RW]
exit_status[R]
obj[R]

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

pid[R]

Only populated when calling via Rye::Shell

set[R]

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

stderr[R]

An array containing any STDERR output

### Public Class Methods

new(obj, *args) click to toggle source

- `obj` an instance of Rye::Box or Rye::Set

- `args` anything that can sent to Array#new

    # File lib/rye/rap.rb, line 33
    def initialize(obj, *args)
      @obj = obj
      @exit_status = -1
      @stderr = []
      super *args
    end

### Public Instance Methods

>(path) click to toggle source

Output STDOUT content to (remote) `path` This works like a shell redirect so the file contents are cleared before outputting.

    rbox.ps('aux') > 'processes.log'

    # File lib/rye/rap.rb, line 108
    def >(path)
      self.obj.unsafely { rm path }
      self.obj.file_append(path, self)
    end

>>(path) click to toggle source

Output STDOUT content to (remote) `path` This works like a shell redirect so if the target file exists the STDOUT content will be appended.

    rbox.ps('aux') >> 'processes.log'

    # File lib/rye/rap.rb, line 119
    def >>(path)
      self.obj.file_append(path, self)
    end

add_exit_status(code) click to toggle source

Parse the exit code.

- `code` an exit code string or integer or Process::Status object

For example, when running a command via Rye.shell, this method is send $? which is Process::Status object. Via Rye::Box.run_command it's just an exit code returned by Net::SSH.

In JRuby, if `code` is a Process::Status object, @pid will be set to -1 (JRuby doesn't return the pid).

Returns the exit code as an Integer.

    # File lib/rye/rap.rb, line 86
    def add_exit_status(code)
      code = 0 if code.nil?
      if code.is_a?(Process::Status)
        @exit_status = code.exitstatus.to_i
        @pid = Rye.sysinfo.vm == :java ? '-1' : code.pid
      else
        @exit_status = code.to_i
      end
    end

add_stderr(*args) click to toggle source

Add STDERR output from the command executed via SSH.

    # File lib/rye/rap.rb, line 56
    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) click to toggle source

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).

    # File lib/rye/rap.rb, line 69
    def add_stdout(*args)
      args = args.flatten.compact
      args = args.first.split($/) if args.size == 1
      self << args
      self.flatten!
    end

code() click to toggle source

    # File lib/rye/rap.rb, line 95
    def code; @exit_status; end

inspect() click to toggle source

    # File lib/rye/rap.rb, line 43
    def inspect
      "[%s, %s, %s, %s]" % [self.join("").tr("\r", ''), @stderr.join("; ").tr("\r", ''), exit_status, exit_signal]
    end

stdout() click to toggle source

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.

    # File lib/rye/rap.rb, line 51
    def stdout
      self
    end

to_s() click to toggle source

Returns the first element if there's only the one, an empty String if there's none. Returns the value of self.join($/) otherwise.

    # File lib/rye/rap.rb, line 100
    def to_s; self.join $/; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.