Class: RightConf::FileReporter
- Inherits:
-
BaseReporter
- Object
- BaseReporter
- RightConf::FileReporter
- Defined in:
- lib/rconf/progress_reporters/file_reporter.rb
Overview
File progress reporter, logs progress to file
Instance Method Summary collapse
-
#initialize(path) ⇒ FileReporter
constructor
Set filename and check file can be written to Create file directory if needed.
-
#write(lines) ⇒ Object
Write lines to progress report file, prepend timestamp.
Methods inherited from BaseReporter
#method_missing, #report_result
Constructor Details
#initialize(path) ⇒ FileReporter
Set filename and check file can be written to Create file directory if needed
Parameters
- path(String)
-
Path to progress reports file
Raise
- (Exception)
-
If progress report file is not writable
25 26 27 28 29 30 |
# File 'lib/rconf/progress_reporters/file_reporter.rb', line 25 def initialize(path) FileUtils.mkdir_p(File.dirname(path)) system("touch #{path}") raise "Could not initialize progress report file #{path}" unless $?.success? @path = path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RightConf::BaseReporter
Instance Method Details
#write(lines) ⇒ Object
Write lines to progress report file, prepend timestamp
Parameters
- lines(Array|String)
-
Lines to be written as array of strings or strings
Return
- true
-
Always return true
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rconf/progress_reporters/file_reporter.rb', line 39 def write(lines) lines = '' if lines.nil? lines = lines.split("\n") if lines.is_a?(String) lines = lines.flatten begin File.open(@path, 'a') do |f| lines.each do |line| f.puts Time.now.strftime("[%m/%d/%Y %H:%M:%S] ") + line end end rescue Exception => e puts lines.join("\n") end true end |