Sha256: 908b59bed15648f939898f50da4e292df4b0610a09d229ff47f5d0ef38b3b703

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'insxsync'

# represents a single config file
class ConfigFile < ErrorHandlingIface
  # reads in the contents of the specified config file and returns the object
  # @param [String] file The full file name of the config file
  def initialize(file)
    # ensure the file is passed properly as a string and exists
    failValidation if file.nil? or not file.is_a?(String) or not File.exists?(file)

    # read in the contents
    @contents = File.open(file, 'r').read
  end

  # Scrub the contents of the config file and return them
  # @return [String] The scrubbed contents of the config file
  def scrub
    @scrubbed = @contents
    @scrubbed.gsub!("\"", "'")
    @scrubbed.gsub!(/params.hostname(\s*)=(\s*)'[^']*'/m, "params.hostname\\1=\\2''")
    @scrubbed.gsub!(/params.username(\s*)=(\s*)'[^']*'/m, "params.username\\1=\\2''")
    @scrubbed.gsub!(/params.password(\s*)=(\s*)'[^']*'/m, "params.password\\1=\\2''")
    @scrubbed.gsub!(/BucketName(\s*)=(\s*)'[^']*'/m, "BucketName\\1=\\2''")

    @scrubbed.gsub!(/\s*useAnalytics\s*=\s*\d*/m, '')
    @scrubbed.gsub!(/\s*useTrackingCode \s*=\s*\d*/m, '')

    @scrubbed.chomp!
    @scrubbed += "\nDebug = 1"
  end

  private

  def get_usage
    #Usage cases for all the usage in this class
    if @usage.nil?
      init_usage
      @usage['new'] = ['file = String']
    end

    super
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
insxsync-1.1.0 lib/config_file.rb
insxsync-1.0.1 lib/config_file.rb
insxsync-1.0.0 lib/config_file.rb
insxsync-0.0.14 lib/config_file.rb