Class: Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudstack/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cloudstack/configuration.rb', line 9

def initialize
  if defined?(Rails) and File.exist?(File.expand_path('config/cloudstack.yml', Rails.root))
    config = YAML.load_file(File.expand_path('config/cloudstack.yml', Rails.root))[Rails.env]

    @api_key = config['api_key'] if config['api_key'].present?
    @secret_key = config['secret_key'] if config['secret_key'].present?
    @api_url = config['api_url'] if config['api_url'].present?
    @api_mode = config['api_mode'] if config['api_mode'].present?
  end
  @api_spec = YAML.load_file(File.expand_path('../../config/api_spec.yml', __FILE__))

  # contain map of underscore api commands relative to camelize
  @method_to_command = Hash[ @api_spec.keys.map {|key| [key.underscore.to_sym, key]} ]
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/cloudstack/configuration.rb', line 3

def api_key
  @api_key
end

#api_modeObject

Returns the value of attribute api_mode.



3
4
5
# File 'lib/cloudstack/configuration.rb', line 3

def api_mode
  @api_mode
end

#api_specObject

Returns the value of attribute api_spec.



3
4
5
# File 'lib/cloudstack/configuration.rb', line 3

def api_spec
  @api_spec
end

#api_urlObject

Returns the value of attribute api_url.



3
4
5
# File 'lib/cloudstack/configuration.rb', line 3

def api_url
  @api_url
end

#secret_keyObject

Returns the value of attribute secret_key.



3
4
5
# File 'lib/cloudstack/configuration.rb', line 3

def secret_key
  @secret_key
end

Instance Method Details

#command_params(command) ⇒ Object

return an array of given command parameters



49
50
51
# File 'lib/cloudstack/configuration.rb', line 49

def command_params(command)
  @api_spec[command.to_s]['params'].keys.map(&:to_sym) if @api_spec[command.to_s]
end

#command_required_params(command) ⇒ Object

return an array of given command required parameters



55
56
57
# File 'lib/cloudstack/configuration.rb', line 55

def command_required_params(command)
  @api_spec[command.to_s]['params'].map {|k,v| k.to_sym if v['required']}.compact
end

#commandsObject

return an array of available api commands. It uses in validations and so on.



36
37
38
# File 'lib/cloudstack/configuration.rb', line 36

def commands
  @api_commands ||= @api_spec.keys
end

#method_to_command(command) ⇒ Object

convert underscored method name to camelCased command



43
44
45
# File 'lib/cloudstack/configuration.rb', line 43

def method_to_command(command)
  @method_to_command[command.to_sym]
end

#methodsObject

return an array of api methods. Method is an underscored command. it was done, because ruby methods should be underscored, but CloudStack uses camelCased command names



29
30
31
# File 'lib/cloudstack/configuration.rb', line 29

def methods
  @api_methods ||= @api_spec.keys.map{ |key| key.underscore.to_sym }
end