Sha256: 66535f245b688d73d1474b08aa01e73c60327245c8ccf0cb3b7d0b6f5eeda437

Contents?: true

Size: 1000 Bytes

Versions: 2

Compression:

Stored size: 1000 Bytes

Contents

#!/usr/bin/env ruby

require 'yaml'

module Gem
  class ConfigFile
    attr_reader :backtrace, :args

    def initialize(arg_list)
      handle_arguments(arg_list)
      if File.exist?(config_file_name)
	@hash = open(config_file_name) { |f| YAML.load(f) }
      else
	@hash = {}
      end
    end

    def config_file_name
      @config_file_name || default_config_file_name
    end

    def [](key)
      @hash[key.to_s]
    end

    private

    def handle_arguments(arg_list)
      need_cfg_name = false
      @args = []
      arg_list.each do |arg|
	if need_cfg_name
	  @config_file_name = arg
	  need_cfg_name = false
	else
	  case arg
	  when /^--backtrace$/
	    @backtrace = true
          when /^--debug$/
            $DEBUG = true
	  when /^--config-file$/
	    need_cfg_name = true
	  when /^--config-file=(.+)$/
	    @config_file_name = $1
	  else
	    @args << arg
	  end
	end
      end
    end

    def default_config_file_name
      File.join(ENV['HOME'], '.gemrc')
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubygems-update-0.8.3 lib/rubygems/config_file.rb
rubygems-update-0.8.4 lib/rubygems/config_file.rb