Sha256: 2bd61f10309eedb0f818bff4f8c0c75702bb7019c08beacb1294c9f93c6f19af

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require_relative '../value_equality'
require_relative 'resource_change'
require_relative 'output_change'

module RubyTerraform
  module Models
    class Plan
      include ValueEquality

      def initialize(content)
        @content = symbolise_keys(content)
      end

      def format_version
        @content[:format_version]
      end

      def terraform_version
        @content[:terraform_version]
      end

      def variables
        (@content[:variables] || {})
      end

      def variable_values
        variables.transform_values { |value| value[:value] }
      end

      def resource_changes
        (@content[:resource_changes] || [])
          .map do |resource_change|
          ResourceChange.new(resource_change)
        end
      end

      def resource_changes_matching(definition)
        resource_changes.filter do |resource_change|
          definition.all? do |method, value|
            resource_change.send(method) == value
          end
        end
      end

      def output_changes
        (@content[:output_changes] || [])
          .map do |output_name, output_change|
          OutputChange.new(output_name, output_change)
        end
      end

      def output_changes_matching(definition)
        output_changes.filter do |output_change|
          definition.all? do |method, value|
            output_change.send(method) == value
          end
        end
      end

      def inspect
        @content.inspect
      end

      def to_h
        @content
      end

      def state
        [@content]
      end

      private

      def symbolise_keys(object)
        if object.is_a?(Hash)
          object.to_h { |k, v| [k.to_sym, symbolise_keys(v)] }
        else
          object
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-terraform-1.8.0.pre.6 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.8.0.pre.5 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.8.0.pre.4 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.8.0.pre.3 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.8.0.pre.2 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.8.0.pre.1 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.7.0 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.7.0.pre.19 lib/ruby_terraform/models/plan.rb
ruby-terraform-1.7.0.pre.18 lib/ruby_terraform/models/plan.rb