Class: Terraspace::Compiler::Strategy::Tfvar
- Inherits:
-
Object
- Object
- Terraspace::Compiler::Strategy::Tfvar
- Defined in:
- lib/terraspace/compiler/strategy/tfvar.rb,
lib/terraspace/compiler/strategy/tfvar/rb.rb,
lib/terraspace/compiler/strategy/tfvar/base.rb,
lib/terraspace/compiler/strategy/tfvar/layer.rb,
lib/terraspace/compiler/strategy/tfvar/tfvars.rb
Defined Under Namespace
Classes: Base, Layer, Rb, Tfvars
Instance Method Summary collapse
-
#initialize(mod) ⇒ Tfvar
constructor
A new instance of Tfvar.
- #layer_paths ⇒ Object
-
#ordered_name(layer_path) ⇒ Object
Tact on number to ensure that tfvars will be processed in desired order.
- #run ⇒ Object
- #strategy_class(ext) ⇒ Object
Constructor Details
#initialize(mod) ⇒ Tfvar
Returns a new instance of Tfvar.
3 4 5 6 |
# File 'lib/terraspace/compiler/strategy/tfvar.rb', line 3 def initialize(mod) @mod = mod @order = 0 end |
Instance Method Details
#layer_paths ⇒ Object
33 34 35 |
# File 'lib/terraspace/compiler/strategy/tfvar.rb', line 33 def layer_paths Layer.new(@mod).paths end |
#ordered_name(layer_path) ⇒ Object
Tact on number to ensure that tfvars will be processed in desired order. Also name auto.tfvars so it will automatically load
25 26 27 28 29 30 31 |
# File 'lib/terraspace/compiler/strategy/tfvar.rb', line 25 def ordered_name(layer_path) @order += 1 prefix = @order.to_s.rjust(2, '0') # add leading 0 in case there are more than 10 layers name = "#{prefix}-#{File.basename(layer_path)}" name.sub('.tfvars','.auto.tfvars') .sub('.rb','.auto.tfvars.json') end |
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/terraspace/compiler/strategy/tfvar.rb', line 8 def run layer_paths.each do |layer_path| ext = File.extname(layer_path).sub('.','') klass = strategy_class(ext) next unless klass strategy = klass.new(@mod, layer_path) content = strategy.run dest_name = ordered_name(layer_path) writer = Terraspace::Compiler::Writer.new(@mod, dest_name: dest_name) writer.write(content) end end |
#strategy_class(ext) ⇒ Object
37 38 39 40 |
# File 'lib/terraspace/compiler/strategy/tfvar.rb', line 37 def strategy_class(ext) "Terraspace::Compiler::Strategy::Tfvar::#{ext.camelize}".constantize rescue NameError end |