Class: Mccloud::Config::Provider
- Inherits:
-
Object
- Object
- Mccloud::Config::Provider
- Defined in:
- lib/mccloud/config/provider.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #define(name) {|provider_stub| ... } ⇒ Object
-
#initialize(config) ⇒ Provider
constructor
A new instance of Provider.
Constructor Details
#initialize(config) ⇒ Provider
Returns a new instance of Provider.
11 12 13 14 |
# File 'lib/mccloud/config/provider.rb', line 11 def initialize(config) @env=config.env @components=Hash.new end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
8 9 10 |
# File 'lib/mccloud/config/provider.rb', line 8 def components @components end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/mccloud/config/provider.rb', line 9 def env @env end |
Instance Method Details
#define(name) {|provider_stub| ... } ⇒ Object
16 17 18 19 20 21 22 23 24 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/mccloud/config/provider.rb', line 16 def define(name) # We do this for vagrant syntax # Depending on type, we create a variable of that type # f.i. component_stub.vm or component_stub.lb provider_stub=OpenStruct.new provider_stub.provider=OpenStruct.new env.logger.debug("config provider"){ "Start stubbing provider"} # Now we can 'execute' the config file using our stub component # For guessing the provider type yield provider_stub env.logger.debug("config provider"){ "End stubbing provider"} # After processing we extract the provider type and options again provider_type=provider_stub.provider.flavor env.logger.debug("config provider"){ "Found provider of type #{provider_type}"} =provider_stub.provider. begin # Now that we know the actual provider, we can check if the provider has this type of component require_path='mccloud/provider/'+provider_type.to_s.downcase+"/provider" require require_path # Now we can create the real provider real_provider=Object.const_get("Mccloud").const_get("Provider").const_get(provider_type.to_s.capitalize).const_get("Provider").new(name,,env) provider_stub.provider=real_provider yield provider_stub env.logger.debug("config provider"){ "Instantiating provider #{name.to_s}"} components[name.to_s]=provider_stub.provider rescue ::Mccloud::Error => ex raise ::Mccloud::Error, "Error loading provider with #{name}\n#{ex}" end end |