Sha256: 00133d28f84b75662051d76659dc30d8a4346c8c5d668b4f3ebec62ae88a7b43

Contents?: true

Size: 1.68 KB

Versions: 79

Compression:

Stored size: 1.68 KB

Contents

# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
#
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
# AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
# reproduction, modification, or disclosure of this program is
# strictly prohibited. Any use of this program by an authorized
# licensee is strictly subject to the terms and conditions,
# including confidentiality obligations, set forth in the applicable
# License Agreement between RightScale.com, Inc. and
# the licensee

module RightConf

  # File progress reporter, logs progress to file
  class FileReporter < BaseReporter

    # 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
    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

    # 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
    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

  end
end


Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
rconf-0.9.18 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.17 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.12 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.11 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.10 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.9 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.8 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.7 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.6 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.4 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.30 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.29 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.21 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.20 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.19 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.18 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.17 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.16 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.15 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.8.14 lib/rconf/progress_reporters/file_reporter.rb