Sha256: 8d29fb83e312d2dc7acd99bb53233ee6d54b73672941d59aafdeb31d225fa344

Contents?: true

Size: 1.73 KB

Versions: 22

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require_relative '../value_equality'
require_relative 'change'

module RubyTerraform
  module Models
    class ResourceChange
      include ValueEquality

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

      def address
        @content[:address]
      end

      def module_address
        @content[:module_address]
      end

      def mode
        @content[:mode]
      end

      def type
        @content[:type]
      end

      def name
        @content[:name]
      end

      def index
        @content[:index]
      end

      def provider_name
        @content[:provider_name]
      end

      def change
        Change.new(@content[:change])
      end

      def no_op?
        change.no_op?
      end

      def create?
        change.create?
      end

      def read?
        change.read?
      end

      def update?
        change.update?
      end

      def replace_delete_before_create?
        change.replace_delete_before_create?
      end

      def replace_create_before_delete?
        change.replace_create_before_delete?
      end

      def replace?
        change.replace?
      end

      def delete?
        change.delete?
      end

      def present_before?
        no_op? || read? || update? || replace? || delete?
      end

      def present_after?
        no_op? || read? || create? || update? || replace?
      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

22 entries across 22 versions & 1 rubygems

Version Path
ruby-terraform-1.7.0.pre.16 lib/ruby_terraform/models/resource_change.rb
ruby-terraform-1.7.0.pre.15 lib/ruby_terraform/models/resource_change.rb