Class: Pangea::Entities::Namespace::State

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/pangea/entities/namespace.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(attributes) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pangea/entities/namespace.rb', line 49

def self.new(attributes)
  attrs = attributes.is_a?(Hash) ? attributes : {}
  state_type = attrs[:type]
  config_attrs = attrs[:config] || {}

  if state_type == :s3
    required_fields = [:bucket, :key]
    missing_fields = required_fields.select { |field| config_attrs[field].nil? || config_attrs[field].empty? }
    unless missing_fields.empty?
      raise ::Pangea::Entities::ValidationError, "S3 backend requires: #{missing_fields.join(', ')}"
    end
  elsif state_type == :local
    config_attrs[:path] ||= "./terraform.tfstate"
  end

  super(attrs)
end

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/pangea/entities/namespace.rb', line 71

def local?
  type == :local
end

#s3?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/pangea/entities/namespace.rb', line 67

def s3?
  type == :s3
end