Class: CorrectHorseBatteryStaple::Writer::File
- Inherits:
-
Base
- Object
- CorrectHorseBatteryStaple::Writer
- Base
- CorrectHorseBatteryStaple::Writer::File
- Defined in:
- lib/correct_horse_battery_staple/writer/file.rb
Overview
base class for file-based stores
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
Attributes inherited from Base
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(dest, options = {}) ⇒ File
constructor
A new instance of File.
Methods inherited from Base
Methods included from Common
#array_sample, #logger, #random_in_range, #random_number, #set_sample
Methods inherited from CorrectHorseBatteryStaple::Writer
Constructor Details
#initialize(dest, options = {}) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 8 def initialize(dest, = {}) super @do_close = false if dest.respond_to?(:write) self.io = dest else if ["/dev/stdout", "-"].include?(dest) self.io = STDOUT else self.io = open(dest, openmode) @do_close = true end end end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
6 7 8 |
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 6 def io @io end |
Instance Method Details
#close ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 24 def close return unless @do_close self.io.close rescue nil ensure self.io = nil @do_close = false end |