Sha256: 33b4f14e10b09bad46571d2a777865f930297d51c9d305e808e931e6ee9c3493

Contents?: true

Size: 920 Bytes

Versions: 3

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

require 'json'

require_relative 'base'

module RubyTerraform
  module Options
    module Types
      class Standard < Base
        def apply(builder)
          if value.respond_to?(:keys)
            apply_hash(builder)
          elsif value.respond_to?(:each)
            apply_array(builder)
          else
            builder.with_option(name, value)
          end
        end

        private

        def apply_hash(builder)
          builder.with_repeated_option(
            name,
            value.map do |hash_key, hash_value|
              "'#{hash_key}=#{as_string(hash_value)}'"
            end,
            separator: ' '
          )
        end

        def apply_array(builder)
          builder.with_repeated_option(name, value)
        end

        def as_string(value)
          value.is_a?(String) ? value : JSON.generate(value)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-terraform-0.65.0.pre.11 lib/ruby_terraform/options/types/standard.rb
ruby-terraform-0.65.0.pre.10 lib/ruby_terraform/options/types/standard.rb
ruby-terraform-0.65.0.pre.9 lib/ruby_terraform/options/types/standard.rb