Class: Rubish::Executable::ExecutableIO
- Inherits:
-
Object
- Object
- Rubish::Executable::ExecutableIO
- Defined in:
- lib/rubish/executable.rb
Instance Attribute Summary collapse
-
#auto_close ⇒ Object
readonly
Returns the value of attribute auto_close.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
-
.ios(*specs) ⇒ Object
transactionally open a bunch of ios if one fails to open, close all others.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io, auto_close, thread) ⇒ ExecutableIO
constructor
A new instance of ExecutableIO.
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_close ⇒ Object (readonly)
Returns the value of attribute auto_close.
88 89 90 |
# File 'lib/rubish/executable.rb', line 88 def auto_close @auto_close end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
87 88 89 |
# File 'lib/rubish/executable.rb', line 87 def io @io end |
#thread ⇒ Object (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
#close ⇒ Object
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 |