Class: Commands::Datas::Data
Overview
A CommandData instance contains all information returned by a Command#run:
* It's exit status:
- Exit number.
- Signals
- ...
* It's outputs:
- What it writes on stdout.
- stderr.
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#input ⇒ Object
Returns the value of attribute input.
-
#open_mode ⇒ Object
Returns the value of attribute open_mode.
-
#output ⇒ Object
Returns the value of attribute output.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #clean ⇒ Object
- #display(out = STDOUT, err = STDERR) ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #kill(sig = 'KILL') ⇒ Object
- #method_missing(meth, *a, &b) ⇒ Object
- #to_yaml_string ⇒ Object
- #waitpid ⇒ Object
-
#|(rhs) ⇒ Object
FIXME CHECK ME.
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
32 33 34 35 36 |
# File 'lib/commands/datas/data.rb', line 32 def initialize @open_mode = :w @status, @pid = nil, nil @@datas << self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *a, &b) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/commands/datas/data.rb', line 59 def method_missing ( meth, *a, &b ) if output.respond_to?(meth) output.send(meth, *a, &b) else super end end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
26 27 28 |
# File 'lib/commands/datas/data.rb', line 26 def error @error end |
#input ⇒ Object
Returns the value of attribute input.
24 25 26 |
# File 'lib/commands/datas/data.rb', line 24 def input @input end |
#open_mode ⇒ Object
Returns the value of attribute open_mode.
28 29 30 |
# File 'lib/commands/datas/data.rb', line 28 def open_mode @open_mode end |
#output ⇒ Object
Returns the value of attribute output.
25 26 27 |
# File 'lib/commands/datas/data.rb', line 25 def output @output end |
#pid ⇒ Object
Returns the value of attribute pid.
23 24 25 |
# File 'lib/commands/datas/data.rb', line 23 def pid @pid end |
#status ⇒ Object
Returns the value of attribute status.
27 28 29 |
# File 'lib/commands/datas/data.rb', line 27 def status @status end |
Class Method Details
.clean_all ⇒ Object
150 151 152 |
# File 'lib/commands/datas/data.rb', line 150 def self.clean_all @@datas.dup.each { |data| data.clean } end |
Instance Method Details
#clean ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/commands/datas/data.rb', line 132 def clean kill [input, output, error].each do |stream| next if stream.nil? or stream.is_a? IO if stream.is_a? File stream.close stream = stream.path.to_path end if stream.is_a? Pathname stream.unlink if stream.exist? and stream.temp? elsif stream.respond_to? :clean stream.clean else raise ArgumentError, "must at least respond to :clean (#{stream})" end end end |
#display(out = STDOUT, err = STDERR) ⇒ Object
68 69 70 71 72 |
# File 'lib/commands/datas/data.rb', line 68 def display ( out=STDOUT, err=STDERR ) waitpid out.print @output.read err.print @error.read end |
#kill(sig = 'KILL') ⇒ Object
127 128 129 130 |
# File 'lib/commands/datas/data.rb', line 127 def kill ( sig='KILL' ) Process.kill sig, @pid if @status.nil? and not @pid.nil? waitpid end |
#to_yaml_string ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/commands/datas/data.rb', line 108 def to_yaml_string suppress(IOError) { out = output.read } suppress(IOError) { err = error.read } out ||= '' err ||= '' msg = [] msg << "exit: #{status.exitstatus}" unless status.nil? unless out.empty? out.gsub!(/^/, ' ') msg << "output: |\n #{out}" end unless err.empty? err.gsub!(/^/, ' ') msg << "error: |\n #{err}" end "\n" + msg.join("\n") end |
#waitpid ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/commands/datas/data.rb', line 39 def waitpid return @status unless @status.nil? return if @pid.nil? Process.waitpid(@pid) @status = $? @@datas.delete(self) self end |