Class: Eien::Renderers::DeploymentRenderer

Inherits:
Renderer
  • Object
show all
Defined in:
lib/eien/renderers/deployment_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::TimeHelpers

#summarize_age

Constructor Details

#initialize(deployment) ⇒ DeploymentRenderer

Returns a new instance of DeploymentRenderer.



8
9
10
11
# File 'lib/eien/renderers/deployment_renderer.rb', line 8

def initialize(deployment)
  @deployment = deployment
  super()
end

Instance Attribute Details

#deploymentObject (readonly)

Returns the value of attribute deployment.



6
7
8
# File 'lib/eien/renderers/deployment_renderer.rb', line 6

def deployment
  @deployment
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eien/renderers/deployment_renderer.rb', line 13

def render
  status = deployment.status

  condition_message = status.conditions.map do |condition|
    condition_update_time_ago = summarize_age(Time.parse(condition.lastTransitionTime))
    "#{colorize_condition_type(condition.type)}\n#{condition.message}\n#{condition_update_time_ago} ago\n"
  end.join("\n")

  rows = [
    ["name", ColorizedString.new(name).light_magenta],
    ["", ""],
    ["created", "#{summarize_age(created_at)} ago"],
    ["", ""],
    ["replicas", [
      "#{status.replicas} desired",
      "#{status.updatedReplicas} updated",
      "#{status.readyReplicas} ready",
      "#{status.availableReplicas} available",
    ].join("\n"),],
    ["", ""],
    ["condition", condition_message],
  ]
  TTY::Table.new(rows).render(:unicode, multiline: true, padding: [0, 1])
end