Class: RightScaleCLI::Config
- Inherits:
-
Object
- Object
- RightScaleCLI::Config
- Defined in:
- lib/rightscale_cli/config.rb
Overview
Represents a RightScale CLI configuration
Instance Attribute Summary collapse
-
#config_home ⇒ Object
Returns the value of attribute config_home.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#directives ⇒ Object
Returns the value of attribute directives.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
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_home ⇒ Object
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_path ⇒ Object
Returns the value of attribute config_path.
23 24 25 |
# File 'lib/rightscale_cli/config.rb', line 23 def config_path @config_path end |
#directives ⇒ Object
Returns the value of attribute directives.
23 24 25 |
# File 'lib/rightscale_cli/config.rb', line 23 def directives @directives end |
#template_path ⇒ Object
Returns the value of attribute template_path.
23 24 25 |
# File 'lib/rightscale_cli/config.rb', line 23 def template_path @template_path end |