Sha256: 283e5874f6ea5e708a639ece34752a90f9cd6f8a678ef6a34bd4949b37bcdab0

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

module Terraspace::Terraform::RemoteState
  class OutputProxy
    # raw: can be anything: String, Array, Hash, etc
    # options: original options passed by user from the output helper in tfvars
    attr_reader :raw, :options
    def initialize(mod, raw, options={})
      @mod, @raw, @options = mod, raw, options
      @format = @options[:format]
    end

    # Should always return a String
    def to_s
      if @mod.resolved
        # Dont use NullObject wrapper because Integer get changed to Strings.
        # Want raw value to be used for the to_json call
        value = @raw.nil? ? mock_or_error : @raw
        value.to_json
      else
        NullObject.new # to_s => (unresolved)
      end
    end

    def to_ruby
      data = @raw.nil? ? mock_or_error : @raw
      @mod.resolved ? data : NullObject.new
    end

  private
    def mock_or_error
      @options[:mock] || @options[:error]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
terraspace-0.3.6 lib/terraspace/terraform/remote_state/output_proxy.rb
terraspace-0.3.5 lib/terraspace/terraform/remote_state/output_proxy.rb