Class: RGen::ModelBuilder::BuilderContext::ExtensionContainerFactory
- Inherits:
-
Object
- Object
- RGen::ModelBuilder::BuilderContext::ExtensionContainerFactory
- Defined in:
- lib/rgen/model_builder/builder_context.rb
Defined Under Namespace
Classes: ExtensionContainer
Instance Method Summary collapse
- #extensionContainer(package) ⇒ Object
-
#initialize(rootPackage, extensionsModule, builderContext) ⇒ ExtensionContainerFactory
constructor
A new instance of ExtensionContainerFactory.
- #moduleForPackage(package) ⇒ Object
Constructor Details
#initialize(rootPackage, extensionsModule, builderContext) ⇒ ExtensionContainerFactory
Returns a new instance of ExtensionContainerFactory.
124 125 126 127 |
# File 'lib/rgen/model_builder/builder_context.rb', line 124 def initialize(rootPackage, extensionsModule, builderContext) @rootPackage, @extensionsModule, @builderContext = rootPackage, extensionsModule, builderContext @extensionContainer = {} end |
Instance Method Details
#extensionContainer(package) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/rgen/model_builder/builder_context.rb', line 147 def extensionContainer(package) return @extensionContainer[package] if @extensionContainer[package] container = ExtensionContainer.new(@builderContext) extensionModule = moduleForPackage(package) container.extend(extensionModule) if extensionModule @extensionContainer[package] = container end |
#moduleForPackage(package) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rgen/model_builder/builder_context.rb', line 129 def moduleForPackage(package) qName = package.qualifiedName rqName = @rootPackage.qualifiedName raise "Package #{qName} is not contained within #{rqName}" unless qName.index(rqName) == 0 path = qName.sub(rqName,'').split('::') path.shift if path.first == "" mod = @extensionsModule path.each do |p| if mod && mod.const_defined?(p) mod = mod.const_get(p) else mod = nil break end end mod end |