lib/mkit/app/helpers/services_helper.rb in mkit-0.4.2 vs lib/mkit/app/helpers/services_helper.rb in mkit-0.4.3

- old
+ new

@@ -6,25 +6,27 @@ def format_response(data, _verbose = false) table = Text::Table.new table.head = %w[id name addr ports pods status] if data.respond_to? 'each' data.each do |srv| - ports = srv.service_port&.each.map { |p| "#{p.mode}/#{p.external_port}" }.join(',') - pods = srv.pod.each.map { |p| p.name.to_s }.join(' ') - table.rows << [srv.id, srv.name, srv.lease&.ip, ports, pods, srv.status] + table.rows << build_table_row(srv) end else - ports = data.service_port&.each.map { |p| "#{p.mode}/#{p.external_port}" }.join(',') - pods = data.pod.each.map { |p| p.name.to_s }.join(' ') - table.rows << [data.id, data.name, data.lease&.ip, ports, pods, data.status] + table.rows << build_table_row(data) end table.to_s end def find_by_id_or_name srv = Service.find_by_id(params[:id]) srv ||= Service.find_by_name(params[:id]) error 404, "Couldn't find Service '#{params[:id]}'\n" unless srv srv + end + + def build_table_row(data) + ports = data.service_port&.each.map { |p| "#{p.mode}/#{p.external_port}" }.join(',') + pods = data.pod.each.map { |p| p.name.to_s }.join(' ') + [data.id, data.name, data.lease&.ip, ports, pods, data.status] end end end