Sha256: f94fb3a67751e10bff60dc6ce5e38aa960d4d6f1a6004a1d19696e8d9a90040f

Contents?: true

Size: 1.68 KB

Versions: 22

Compression:

Stored size: 1.68 KB

Contents

# Copyright (C) 2011-2012 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

22 entries across 22 versions & 1 rubygems

Version Path
rconf-1.0.13 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.12 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.11 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.10 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.9 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.8 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.7 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.6 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.5 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.4 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.3 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.1 lib/rconf/progress_reporters/file_reporter.rb
rconf-1.0.0 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.10.1 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.10.0 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.25 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.24 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.23 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.22 lib/rconf/progress_reporters/file_reporter.rb
rconf-0.9.21 lib/rconf/progress_reporters/file_reporter.rb