Sha256: d74ada774674da1f64898b5884b9300d34f6445378fc3a94ce68a132a2382f40

Contents?: true

Size: 1.97 KB

Versions: 15

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

15 entries across 15 versions & 1 rubygems

Version Path
ruby-terraform-1.9.0.pre.2 lib/ruby_terraform/models/change.rb
ruby-terraform-1.9.0.pre.1 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.13 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.12 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.11 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.10 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.9 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.8 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.7 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.6 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.5 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.4 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.3 lib/ruby_terraform/models/change.rb
ruby-terraform-1.8.0.pre.2 lib/ruby_terraform/models/change.rb