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.2 lib/terraspace/compiler/expander.rb
terraspace-0.6.1 lib/terraspace/compiler/expander.rb
terraspace-0.6.0 lib/terraspace/compiler/expander.rb
terraspace-0.5.12 lib/terraspace/compiler/expander.rb
terraspace-0.5.11 lib/terraspace/compiler/expander.rb
terraspace-0.5.10 lib/terraspace/compiler/expander.rb
terraspace-0.5.9 lib/terraspace/compiler/expander.rb
terraspace-0.5.8 lib/terraspace/compiler/expander.rb
terraspace-0.5.7 lib/terraspace/compiler/expander.rb
terraspace-0.5.6 lib/terraspace/compiler/expander.rb
terraspace-0.5.5 lib/terraspace/compiler/expander.rb
terraspace-0.5.4 lib/terraspace/compiler/expander.rb
terraspace-0.5.3 lib/terraspace/compiler/expander.rb
terraspace-0.5.2 lib/terraspace/compiler/expander.rb
terraspace-0.5.1 lib/terraspace/compiler/expander.rb
terraspace-0.5.0 lib/terraspace/compiler/expander.rb
terraspace-0.4.4 lib/terraspace/compiler/expander.rb
terraspace-0.4.3 lib/terraspace/compiler/expander.rb
terraspace-0.4.2 lib/terraspace/compiler/expander.rb
terraspace-0.4.1 lib/terraspace/compiler/expander.rb