Module: MKIt::ServicesHelper
- Defined in:
- lib/mkit/app/helpers/services_helper.rb
Instance Method Summary collapse
- #build_port(p) ⇒ Object
- #build_table_row(data) ⇒ Object
- #find_by_id_or_name ⇒ Object
- #find_srv_pod_by_id_or_name(srv) ⇒ Object
- #format_response(data, _verbose = false) ⇒ Object
Instance Method Details
#build_port(p) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mkit/app/helpers/services_helper.rb', line 42 def build_port(p) case p.mode when 'http' if p.ssl? "#{p.mode}s/#{p.external_port}" else "#{p.mode}/#{p.external_port}" end when 'tcp' if p.ssl? "s#{p.mode}/#{p.external_port}" else "#{p.mode}/#{p.external_port}" end else "#{p.mode}/#{p.external_port}" end end |
#build_table_row(data) ⇒ Object
36 37 38 39 40 |
# File 'lib/mkit/app/helpers/services_helper.rb', line 36 def build_table_row(data) ports = data.service_port&.each.map { |p| build_port(p) }.join(',') pods = data.pod.each.map { |p| p.name.to_s }.join(' ') [data.id, data.name, data.lease&.ip, ports, pods, data.status] end |
#find_by_id_or_name ⇒ Object
19 20 21 22 23 24 |
# File 'lib/mkit/app/helpers/services_helper.rb', line 19 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 |
#find_srv_pod_by_id_or_name(srv) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/mkit/app/helpers/services_helper.rb', line 26 def find_srv_pod_by_id_or_name(srv) if params[:pod_id] pod = srv.find_pod_by_id_or_name(params[:pod_id]) error 404, "Service pod not found." unless pod else pod = srv.pod.first end pod end |
#format_response(data, _verbose = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mkit/app/helpers/services_helper.rb', line 6 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| table.rows << build_table_row(srv) end else table.rows << build_table_row(data) end table.to_s end |