Sha256: 7a3d338122ee2f10cd16bb73f53f65d80c80171ce6a07ba7326aba0afa5db0dd

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require 'ruby_terraform'
require 'stringio'

require_relative './command_instantiation'

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Show
          include CommandInstantiation

          def show(parameters, plan_file)
            parameters = show_parameters(parameters, plan_file)

            log_show_starting(parameters, plan_file)
            log_show_using_parameters(parameters)

            stdout = StringIO.new
            show_command(stdout: stdout)
              .execute(parameters)

            log_show_complete

            stdout.string
          end

          private

          def log_show_starting(parameters, plan_file)
            logger&.info(
              "Showing file: '#{plan_file}' in configuration directory: " \
              "'#{parameters[:chdir]}'..."
            )
          end

          def log_show_using_parameters(parameters)
            logger&.debug("Showing using parameters: #{parameters}...")
          end

          def log_show_complete
            logger&.info('Show complete.')
          end

          def show_command(opts = {})
            instantiate_command(RubyTerraform::Commands::Show, opts)
          end

          def show_parameters(parameters, plan_file)
            with_show_plan_file_parameters(
              with_show_standard_parameters(parameters),
              plan_file
            )
          end

          def with_show_standard_parameters(parameters)
            configuration_directory = parameters[:configuration_directory]

            parameters
              .except(:configuration_directory)
              .merge(
                chdir: configuration_directory,
                no_color: true,
                json: true
              )
          end

          def with_show_plan_file_parameters(parameters, plan_file)
            parameters.merge(
              path: plan_file
            )
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rspec-terraform-0.5.0.pre.3 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.2 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.1 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.4.0 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.3.0.pre.1 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.2.0 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.1.0.pre.49 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.1.0.pre.48 lib/rspec/terraform/helpers/actions/show.rb