Class: Mccloud::Config::Collection
- Inherits:
-
Object
- Object
- Mccloud::Config::Collection
- Defined in:
- lib/mccloud/config/collection.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#config ⇒ Object
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #define(name) {|component_stub| ... } ⇒ Object
-
#initialize(type, config) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(type, config) ⇒ Collection
Returns a new instance of Collection.
14 15 16 17 18 19 20 |
# File 'lib/mccloud/config/collection.rb', line 14 def initialize(type,config) @type=type @components=Hash.new @providers=config.providers @config=config @env=config.env end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
8 9 10 |
# File 'lib/mccloud/config/collection.rb', line 8 def components @components end |
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/mccloud/config/collection.rb', line 10 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
12 13 14 |
# File 'lib/mccloud/config/collection.rb', line 12 def env @env end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/mccloud/config/collection.rb', line 9 def type @type end |
Instance Method Details
#define(name) {|component_stub| ... } ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mccloud/config/collection.rb', line 22 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 component_stub=OpenStruct.new component_stub.send("#{@type}=",::Mccloud::Config::Component.new(config)) env.logger.info("config collection"){ "First pass of reading the config"} # Now we can 'execute' the config file using our stub component # For guessing the provider type yield component_stub env.logger.debug("config collection"){ "Stubs collection type #{@type} is loaded"} # After processing we extract the component again component=component_stub.send("#{@type}") # Checking if this component has a base definition provider_name=nil if component.provider.nil? env.logger.debug("config collection"){ "We got an empty provider here"} env.logger.debug("config collection"){ "Trying if there is a definition provider"} unless component.definition.nil? provider_name=env.config.definitions[component.definition].provider end else provider_name=component.provider.to_s end provider=@providers[provider_name] env.logger.debug("config collection"){ "We get here"} if provider.nil? env.ui.warn "Provider #{component.provider.to_s} does not (yet) exist" env.ui.warn "Skipping definition of #{name}" return end unless component.definition.nil? real_component=env.config.definitions[component.definition].to_vm("blub") else real_component=provider.get_component(@type.capitalize,env) end begin # And repeat the same process with a real component env.logger.debug("config collection"){ "Component of #{@type}"} component_stub.send("#{@type}=",real_component) yield component_stub # After processing we extract the component again component=component_stub.send("#{@type}") # And we set the name component.name=name # We set the provider for this component component.provider=provider # And register this component with the provider # if it is a vm, we add to the hash vms # if it is an ip, we add it to the hash ips provider_collection=provider.instance_variable_get("@#{@type}s") env.logger.debug("registering #{name} with provider #{provider.name}") provider_collection[name]=component # And we also add it to the global config element # So we can have all components of a similar type in one place config_collection=@config.instance_variable_get("@#{@type}s") config_collection[name]=component # Now we can ask the component to validate itself #component_stub.validate components[name.to_s]=component rescue Error => e env.ui.error "Error loading component with #{name} of type #{@type} for provider #{component.provider.type}" end end |