Sha256: 9ce95c7523aa9aa4fc7e17be16e123a693f839bd6fe449cd4f0d42422aaf5135

Contents?: true

Size: 1.08 KB

Versions: 53

Compression:

Stored size: 1.08 KB

Contents

module Terraspace::Compiler
  class Expander
    delegate :expand, :expansion, to: :expander

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

    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

    class << self
      extend Memoist

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

      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
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
terraspace-0.6.23 lib/terraspace/compiler/expander.rb
terraspace-0.6.22 lib/terraspace/compiler/expander.rb
terraspace-0.6.21 lib/terraspace/compiler/expander.rb
terraspace-0.6.20 lib/terraspace/compiler/expander.rb
terraspace-0.6.19 lib/terraspace/compiler/expander.rb
terraspace-0.6.18 lib/terraspace/compiler/expander.rb
terraspace-0.6.17 lib/terraspace/compiler/expander.rb
terraspace-0.6.16 lib/terraspace/compiler/expander.rb
terraspace-0.6.15 lib/terraspace/compiler/expander.rb
terraspace-0.6.13 lib/terraspace/compiler/expander.rb
terraspace-0.6.12 lib/terraspace/compiler/expander.rb
terraspace-0.6.11 lib/terraspace/compiler/expander.rb
terraspace-0.6.10 lib/terraspace/compiler/expander.rb
terraspace-0.6.9 lib/terraspace/compiler/expander.rb
terraspace-0.6.8 lib/terraspace/compiler/expander.rb
terraspace-0.6.7 lib/terraspace/compiler/expander.rb
terraspace-0.6.6 lib/terraspace/compiler/expander.rb
terraspace-0.6.5 lib/terraspace/compiler/expander.rb
terraspace-0.6.4 lib/terraspace/compiler/expander.rb
terraspace-0.6.3 lib/terraspace/compiler/expander.rb