Class: RightScaleCLI::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rightscale_cli/config.rb

Overview

Represents a RightScale CLI configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

Instance Attribute Details

#config_homeObject

Returns the value of attribute config_home.



23
24
25
# File 'lib/rightscale_cli/config.rb', line 23

def config_home
  @config_home
end

#config_pathObject

Returns the value of attribute config_path.



23
24
25
# File 'lib/rightscale_cli/config.rb', line 23

def config_path
  @config_path
end

#directivesObject

Returns the value of attribute directives.



23
24
25
# File 'lib/rightscale_cli/config.rb', line 23

def directives
  @directives
end

#template_pathObject

Returns the value of attribute template_path.



23
24
25
# File 'lib/rightscale_cli/config.rb', line 23

def template_path
  @template_path
end