Module: CloudConfig::Providers::ClassMethods

Defined in:
lib/cloud-config/providers.rb

Overview

Class methods for CloudConfig::Providers

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#Fetch provider configuration by setting key(providerconfigurationbysettingkey) ⇒ Hash<Symbol,ProviderConfig> (readonly)

Returns:



19
# File 'lib/cloud-config/providers.rb', line 19

attr_reader :providers_by_key

#Provider configurations(configurations) ⇒ Hash<Symbol,ProviderConfig> (readonly)

Returns:



15
# File 'lib/cloud-config/providers.rb', line 15

attr_reader :providers

#providersObject (readonly)

Returns the value of attribute providers.



15
16
17
# File 'lib/cloud-config/providers.rb', line 15

def providers
  @providers
end

#providers_by_keyObject (readonly)

Returns the value of attribute providers_by_key.



19
20
21
# File 'lib/cloud-config/providers.rb', line 19

def providers_by_key
  @providers_by_key
end

Instance Method Details

#provider(provider_name, provider_options = {}) { ... } ⇒ Object

Add a provider to the list of provider configurations.

Parameters:

  • provider_name (Symbol)

    Name of the provider

  • provider_options (Hash<Symbol,Object>) (defaults to: {})

    Options for configuring the provider

Yields:



27
28
29
30
31
32
33
34
# File 'lib/cloud-config/providers.rb', line 27

def provider(provider_name, provider_options = {}, &blk)
  provider_config = ProviderConfig.new(provider_name, provider_options)
  provider_config.instance_eval(&blk) if blk
  @providers ||= {}
  @providers[provider_name] = provider_config

  update_provider_keys(provider_config)
end

#update_provider_keys(provider_config) ⇒ Object

Update #providers_by_key with settings from the provider config.

Parameters:

  • provider_config (ProviderConfig)

    Provider config containing the keys



39
40
41
42
43
44
# File 'lib/cloud-config/providers.rb', line 39

def update_provider_keys(provider_config)
  @providers_by_key ||= {}
  provider_config.settings.each_key do |key|
    @providers_by_key[key] = provider_config
  end
end