Sha256: e468e3b40568218b830c30e8e6f1dbc570478104c510ea181ef7e4f81416642a

Contents?: true

Size: 842 Bytes

Versions: 8

Compression:

Stored size: 842 Bytes

Contents

module Terraspace::Compiler
  class Backend
    extend Memoist

    def initialize(mod)
      @mod = mod
    end

    def create
      klass = backend_interface(backend_name)
      return unless klass # in case auto-creation is not supported for specific backend

      interface = klass.new(backend_info)
      interface.call
    end

    def backend_name
      backend.keys.first # IE: s3, gcs, etc
    end

    def backend_info
      backend.values.first # structure within the s3 or gcs key
    end

    def backend
      Parser.new(@mod).result
    end
    memoize :backend

    def backend_interface(name)
      return unless name
      # IE: TerraspacePluginAws::Interfaces::Backend
      klass_name = Terraspace::Plugin.klass("Backend", backend: name)
      klass_name.constantize if klass_name
    rescue NameError
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
terraspace-0.3.2 lib/terraspace/compiler/backend.rb
terraspace-0.3.1 lib/terraspace/compiler/backend.rb
terraspace-0.3.0 lib/terraspace/compiler/backend.rb
terraspace-0.2.4 lib/terraspace/compiler/backend.rb
terraspace-0.2.3 lib/terraspace/compiler/backend.rb
terraspace-0.2.2 lib/terraspace/compiler/backend.rb
terraspace-0.2.1 lib/terraspace/compiler/backend.rb
terraspace-0.2.0 lib/terraspace/compiler/backend.rb