Sha256: 75301171a558e27112f28ca6a933384f35916a3a919d4a0ddb5e9fe95e15425f

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require_relative '../configuration/var_captor'

module RSpec
  module Terraform
    module Helpers
      class Var
        attr_reader(:configuration_provider)

        def initialize(opts = {})
          @configuration_provider =
            opts[:configuration_provider] || Configuration.identity_provider
        end

        def execute(overrides = {}, &block)
          parameters = with_configuration_provider_parameters(overrides)
          parameters = with_resolved_vars(parameters, &block)

          parameters[:vars][parameters[:name].to_sym]
        end

        private

        def with_configuration_provider_parameters(parameters)
          configuration_provider.resolve(parameters)
        end

        def with_resolved_vars(parameters, &block)
          return parameters unless block_given?

          var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
          block.call(var_captor)
          parameters.merge(vars: var_captor.to_h)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rspec-terraform-0.1.0.pre.44 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.43 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.42 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.41 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.40 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.39 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.38 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.37 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.36 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.35 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.34 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.33 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.32 lib/rspec/terraform/helpers/var.rb
rspec-terraform-0.1.0.pre.31 lib/rspec/terraform/helpers/var.rb