Class: Pangea::Contracts::ArchitectureResult

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/contracts/architecture_result.rb

Overview

Result object from kubernetes_cluster() — holds all created references. This is the top-level contract returned by the Architecture module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ ArchitectureResult

Returns a new instance of ArchitectureResult.



27
28
29
30
31
32
33
34
# File 'lib/pangea/contracts/architecture_result.rb', line 27

def initialize(name, config)
  @name = name
  @config = config
  @cluster = nil
  @network = nil
  @iam = nil
  @node_pools = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Access outputs from the cluster reference



55
56
57
58
59
60
61
# File 'lib/pangea/contracts/architecture_result.rb', line 55

def method_missing(method_name, *args, &block)
  if cluster&.respond_to?(method_name)
    cluster.public_send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/pangea/contracts/architecture_result.rb', line 24

def config
  @config
end

#iamObject

Returns the value of attribute iam.



25
26
27
# File 'lib/pangea/contracts/architecture_result.rb', line 25

def iam
  @iam
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/pangea/contracts/architecture_result.rb', line 24

def name
  @name
end

#networkObject

Returns the value of attribute network.



25
26
27
# File 'lib/pangea/contracts/architecture_result.rb', line 25

def network
  @network
end

#node_poolsObject (readonly)

Returns the value of attribute node_pools.



24
25
26
# File 'lib/pangea/contracts/architecture_result.rb', line 24

def node_pools
  @node_pools
end

Instance Method Details

#add_node_pool(pool_name, ref) ⇒ Object



50
51
52
# File 'lib/pangea/contracts/architecture_result.rb', line 50

def add_node_pool(pool_name, ref)
  @node_pools[pool_name.to_sym] = ref
end

#clusterObject

Cluster getter — always returns a ClusterResult wrapper



37
38
39
# File 'lib/pangea/contracts/architecture_result.rb', line 37

def cluster
  @cluster
end

#cluster=(value) ⇒ Object

Cluster setter — wraps raw control plane refs in ClusterResult



42
43
44
45
46
47
48
# File 'lib/pangea/contracts/architecture_result.rb', line 42

def cluster=(value)
  @cluster = if value.is_a?(ClusterResult)
               value
             elsif value
               ClusterResult.new(value)
             end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pangea/contracts/architecture_result.rb', line 63

def respond_to_missing?(method_name, include_private = false)
  cluster&.respond_to?(method_name, include_private) || super
end

#to_hObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pangea/contracts/architecture_result.rb', line 67

def to_h
  {
    name: name,
    backend: config.respond_to?(:backend) ? config.backend : nil,
    kubernetes_version: config.respond_to?(:kubernetes_version) ? config.kubernetes_version : nil,
    region: config.respond_to?(:region) ? config.region : nil,
    managed_kubernetes: config.respond_to?(:managed_kubernetes?) ? config.managed_kubernetes? : nil,
    cluster: cluster&.to_h,
    network: network_to_h,
    iam: iam_to_h,
    node_pools: node_pools.transform_values { |np| np.respond_to?(:to_h) ? np.to_h : np }
  }
end