Class: RightScaleCLI::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Config

Returns a new instance of Config.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rightscale_cli/config.rb', line 24

def initialize(*args)
  @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.exists?(@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 => '',
       :password_base64 => '',
       :api_url => 'https://us-4.rightscale.com',
       :api_version => '1.5'
    }
    File.open(@config_path, 'w') {|f| f.write(ERB.new(IO.read(@template_path)).result(binding)) }
  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.



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

def config_home
  @config_home
end

#config_pathObject

Returns the value of attribute config_path.



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

def config_path
  @config_path
end

#directivesObject

Returns the value of attribute directives.



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

def directives
  @directives
end

#template_pathObject

Returns the value of attribute template_path.



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

def template_path
  @template_path
end