Class: Octopusci::IO
- Inherits:
-
Object
- Object
- Octopusci::IO
- Defined in:
- lib/octopusci/io.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
Returns the value of attribute job.
Instance Method Summary collapse
-
#initialize(job) ⇒ IO
constructor
A new instance of IO.
- #read_all_log ⇒ Object
- #read_all_log_as_html ⇒ Object
- #read_all_out ⇒ Object
- #read_all_out_as_html ⇒ Object
- #write_log(msg = "", &block) ⇒ Object
- #write_out(msg = "", &block) ⇒ Object
- #write_raw_output(silently = false, msg = "") {|out_f| ... } ⇒ Object
Constructor Details
#initialize(job) ⇒ IO
Returns a new instance of IO.
7 8 9 |
# File 'lib/octopusci/io.rb', line 7 def initialize(job) @job = job end |
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
5 6 7 |
# File 'lib/octopusci/io.rb', line 5 def job @job end |
Instance Method Details
#read_all_log ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/octopusci/io.rb', line 23 def read_all_log if File.exists?(abs_log_file_path) f = File.open(abs_log_file_path, 'r', :encoding => "BINARY") cont = f.read() f.close return cont else return "" end end |
#read_all_log_as_html ⇒ Object
40 41 42 43 44 |
# File 'lib/octopusci/io.rb', line 40 def read_all_log_as_html out = StringIO.new ::ANSI2HTML::Main.new(read_all_log(), out) return out.string end |
#read_all_out ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/octopusci/io.rb', line 11 def read_all_out if File.exists?(abs_output_file_path) cont = "" f = File.open(abs_output_file_path, 'r', :encoding => "BINARY") cont = f.read() f.close return cont else return "" end end |
#read_all_out_as_html ⇒ Object
34 35 36 37 38 |
# File 'lib/octopusci/io.rb', line 34 def read_all_out_as_html out = StringIO.new ::ANSI2HTML::Main.new(read_all_out(), out) return out.string end |
#write_log(msg = "", &block) ⇒ Object
50 51 52 |
# File 'lib/octopusci/io.rb', line 50 def write_log(msg="", &block) write_raw_output(true, msg, &block) end |
#write_out(msg = "", &block) ⇒ Object
46 47 48 |
# File 'lib/octopusci/io.rb', line 46 def write_out(msg="", &block) write_raw_output(false, msg, &block) end |
#write_raw_output(silently = false, msg = "") {|out_f| ... } ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/octopusci/io.rb', line 54 def write_raw_output(silently=false, msg="") # Make sure that the directory structure is in place for the job output. if !File.directory?(abs_output_base_path) FileUtils.mkdir_p(abs_output_base_path) end # Run the command and output the output to the job file out_f = if silently File.open(abs_log_file_path, 'a') else File.open(abs_output_file_path, 'a') end yield(out_f) if block_given? out_f << msg unless msg.nil? || msg.empty? out_f.close end |