Class: Rubish::Executable::ExecutableIO

Inherits:
Object
  • Object
show all
Defined in:
lib/rubish/executable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, auto_close, thread) ⇒ ExecutableIO

Returns a new instance of ExecutableIO.



90
91
92
93
94
# File 'lib/rubish/executable.rb', line 90

def initialize(io,auto_close,thread)
  @io = io
  @auto_close = auto_close
  @thread = thread
end

Instance Attribute Details

#auto_closeObject (readonly)

Returns the value of attribute auto_close.



88
89
90
# File 'lib/rubish/executable.rb', line 88

def auto_close
  @auto_close
end

#ioObject (readonly)

Returns the value of attribute io.



87
88
89
# File 'lib/rubish/executable.rb', line 87

def io
  @io
end

#threadObject (readonly)

Returns the value of attribute thread.



86
87
88
# File 'lib/rubish/executable.rb', line 86

def thread
  @thread
end

Class Method Details

.ios(*specs) ⇒ Object

transactionally open a bunch of ios if one fails to open, close all others.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubish/executable.rb', line 7

def ios(*specs)
  success = false
  begin
    exe_ios = []
    specs.each do |(spec,mode)|
      exe_ios << prepare_io(spec,mode)
    end
    success =true
    return exe_ios
  ensure
    unless success
      exe_ios.each { |exe_io|
        exe_io.close
      }
    end
  end
end

Instance Method Details

#closeObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rubish/executable.rb', line 96

def close
  if auto_close
    io.close
  else
    #io.flush if io.stat.writable?
    #io.flush rescue true # try flushing
  end
  if thread
    begin
      thread.join
    ensure
      if thread.alive?
        thread.kill
      end
    end
  end
end