class RightScaleCLI::Config

Represents a RightScale CLI configuration

Attributes

config_home[RW]
config_path[RW]
directives[RW]
template_path[RW]

Public Class Methods

new(*) click to toggle source
# File lib/rightscale_cli/config.rb, line 25
def initialize(*)
  @template_path = File.join(File.dirname(__FILE__),
                             '..', 'templates', 'right_api_client.yml.erb')
  @config_home = File.join(ENV['HOME'], '.rightscale')
  @config_path = File.join(@config_home, 'right_api_client.yml')

  Dir.mkdir(@config_home) unless File.exist?(@config_home)
  FileUtils.touch(@config_path)

  # write a fresh file if it does not load/parse
  unless YAML.load_file(@config_path)
    @directives = {
      account_id: '',
      email: nil,
      password_base64: '',
      access_token: '',
      api_url: 'https://us-4.rightscale.com',
      api_version: '1.5'
    }
    File.open(@config_path, 'w') do |f|
      f.write(ERB.new(IO.read(@template_path)).result(binding))
    end
  end

  # load/reload the directives from the file
  @directives = YAML.load_file(@config_path)
end