Class: Cloudshaper::Module
- Inherits:
-
StackElement
- Object
- StackElement
- Cloudshaper::Module
- Defined in:
- lib/cloudshaper/module.rb
Overview
Supports terraform ‘modules’. In our case, we call them submodules because Module is a ruby keyword. We also support directly referencing other ruby-defined modules.
Instance Attribute Summary
Attributes inherited from StackElement
Instance Method Summary collapse
- #build_submodule(file_path, parent_module, child_module) ⇒ Object
-
#initialize(parent_module, &block) ⇒ Module
constructor
A new instance of Module.
Methods included from Aws
#post_processing_aws, taggable?
Constructor Details
#initialize(parent_module, &block) ⇒ Module
Returns a new instance of Module.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cloudshaper/module.rb', line 10 def initialize(parent_module, &block) super(parent_module, &block) if StackModules.has? @fields[:source].to_s mod = StackModules.get @fields[:source].to_s module_path = File.join(Stacks.dir, parent_module.id, mod.name) FileUtils.mkdir_p(module_path) @fields[:source] = File.(module_path) file_path = File.join(module_path, 'stack_module.tf.json') build_submodule(file_path, parent_module, mod) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cloudshaper::StackElement
Instance Method Details
#build_submodule(file_path, parent_module, child_module) ⇒ Object
24 25 26 27 28 |
# File 'lib/cloudshaper/module.rb', line 24 def build_submodule(file_path, parent_module, child_module) return if File.exists? file_path child_module.build(cloudshaper_stack_id: parent_module.id) File.open(file_path, 'w') { |f| f.write(child_module.generate) } end |