Method: Controlplane#latest_image_from

Defined in:
lib/core/controlplane.rb

#latest_image_from(items, app_name: gvc, name_only: true) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/core/controlplane.rb', line 64

def latest_image_from(items, app_name: gvc, name_only: true)
  matching_items = items.select { |item| item["name"].start_with?("#{app_name}:") }

  # Or special string to indicate no image available
  if matching_items.empty?
    name_only ? "#{app_name}:#{NO_IMAGE_AVAILABLE}" : nil
  else
    latest_item = matching_items.max_by { |item| DateTime.parse(item["created"]) }
    name_only ? latest_item["name"] : latest_item
  end
end