Sha256: adfa65fccda963fe577e97824a63878fa64839f1281ae406c65fc2731745d930

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require_relative '../value_equality'
require_relative './objects'

module RubyTerraform
  module Models
    class Change
      include ValueEquality

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

      def actions
        @content[:actions].map do |action|
          {
            'no-op' => :no_op,
            'create' => :create,
            'read' => :read,
            'update' => :update,
            'delete' => :delete
          }[action]
        end
      end

      def before
        @content[:before]
      end

      def before_sensitive
        @content[:before_sensitive]
      end

      def before_object
        Objects.box(before, sensitive: before_sensitive)
      end

      def after
        @content[:after]
      end

      def after_unknown
        @content[:after_unknown]
      end

      def after_sensitive
        @content[:after_sensitive]
      end

      def after_object
        Objects.box(
          after,
          unknown: after_unknown,
          sensitive: after_sensitive
        )
      end

      def no_op?
        actions == [:no_op]
      end

      def create?
        actions == [:create]
      end

      def read?
        actions == [:read]
      end

      def update?
        actions == [:update]
      end

      def replace_delete_before_create?
        actions == %i[delete create]
      end

      def replace_create_before_delete?
        actions == %i[create delete]
      end

      def replace?
        replace_delete_before_create? || replace_create_before_delete?
      end

      def delete?
        actions == [:delete]
      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

7 entries across 7 versions & 1 rubygems

Version Path
ruby-terraform-1.8.0.pre.1 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0.pre.19 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0.pre.18 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0.pre.17 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0.pre.16 lib/ruby_terraform/models/change.rb
ruby-terraform-1.7.0.pre.15 lib/ruby_terraform/models/change.rb