Class: CloudConfig::ProviderConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud-config/provider_config.rb

Overview

A class for storing provider configuration. Use this class to create a new provider and set the provider parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider_name, provider_options) ⇒ ProviderConfig

Create a new instance of CloudConfig::ProviderConfig.

Parameters:

  • provider_name (String, Symbol)

    Name of the provider

  • provider_options (Hash<Symbol,Object>)

    List of provider options



15
16
17
18
19
# File 'lib/cloud-config/provider_config.rb', line 15

def initialize(provider_name, provider_options)
  @provider_name = provider_name
  @provider_options = ProviderOptions.new(provider_options)
  @settings = {}
end

Instance Attribute Details

#provider_nameObject (readonly)

Returns the value of attribute provider_name.



9
10
11
# File 'lib/cloud-config/provider_config.rb', line 9

def provider_name
  @provider_name
end

#provider_optionsObject (readonly)

Returns the value of attribute provider_options.



9
10
11
# File 'lib/cloud-config/provider_config.rb', line 9

def provider_options
  @provider_options
end

#settingsObject (readonly)

Returns the value of attribute settings.



9
10
11
# File 'lib/cloud-config/provider_config.rb', line 9

def settings
  @settings
end

Instance Method Details

#providerObject

Return an instance of the configured provider.

Returns:

  • (Object)

    Instance of the provider



33
34
35
# File 'lib/cloud-config/provider_config.rb', line 33

def provider
  @provider ||= provider_class.new(provider_options.to_h)
end

#provider_classObject

Return the class of the configured provider.

Returns:

  • (Object)

    Class of the provider



40
41
42
43
44
45
46
# File 'lib/cloud-config/provider_config.rb', line 40

def provider_class
  @provider_class ||= if provider_options.klass
                        generate_class(provider_options.klass)
                      else
                        provider_class_from_name(provider_name)
                      end
end

#setting(setting_name, setting_options = {}) ⇒ Object

Store the name of a key with this provider. Provider additional options such as caching.

Parameters:

  • setting_name (String, Symbol)

    Setting key

  • setting_options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (setting_options):

  • List (Hash<Symbol,Object>)

    of options for the key



25
26
27
28
# File 'lib/cloud-config/provider_config.rb', line 25

def setting(setting_name, setting_options = {})
  setting_options = merge_options(setting_options)
  @settings[setting_name] = setting_options
end