Class: Terraspace::Compiler::Expander

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/terraspace/compiler/expander.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, name) ⇒ Expander

Returns a new instance of Expander.



6
7
8
9
# File 'lib/terraspace/compiler/expander.rb', line 6

def initialize(mod, name)
  @mod, @name = mod, name
  @expander = expander_class.new(@mod)
end

Instance Attribute Details

#expanderObject (readonly)

Returns the value of attribute expander.



5
6
7
# File 'lib/terraspace/compiler/expander.rb', line 5

def expander
  @expander
end

Class Method Details

.autodetect(mod, opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/terraspace/compiler/expander.rb', line 22

def autodetect(mod, opts={})
  backend = opts[:backend]
  unless backend
    plugin = find_plugin
    backend = plugin[:backend]
  end
  new(mod, backend)
end

.find_pluginObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/terraspace/compiler/expander.rb', line 32

def find_plugin
  plugins = Terraspace::Plugin.meta
  if plugins.size == 1
    plugins.first[1]
  else
    precedence = %w[aws azurerm google]
    plugin = precedence.find do |provider|
      plugins[provider]
    end
    plugins[plugin]
  end
end

Instance Method Details

#expander_classObject



11
12
13
14
15
16
17
# File 'lib/terraspace/compiler/expander.rb', line 11

def expander_class
  # IE: TerraspacePluginAws::Interfaces::Expander
  klass_name = Terraspace::Plugin.klass("Expander", backend: @name)
  klass_name.constantize if klass_name
rescue NameError
  Terraspace::Plugin::Expander::Generic
end