68 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require "devops-client/output/base"
 | |
| require "devops-client/output/concerns/has_provider"
 | |
| 
 | |
| module Output
 | |
|   class Image < Base
 | |
|     include Concerns::HasProvider
 | |
| 
 | |
|     def table
 | |
|       title, headers, rows = nil, nil, nil
 | |
|       if outputting_list?
 | |
|         title = I18n.t("output.title.image.list")
 | |
|         headers, rows = create_list(@data, provider_given?)
 | |
|       else
 | |
|         title = I18n.t("output.title.image.show", :id => @data["id"])
 | |
|         headers, rows = create_show
 | |
|       end
 | |
|       create_table headers, rows, title, with_num?
 | |
|     end
 | |
| 
 | |
|     def csv
 | |
|       title, headers, rows = nil, nil, nil
 | |
|       if !@data.nil?
 | |
|         headers, rows = create_list(@data, provider_given?)
 | |
|       elsif !@data.nil?
 | |
|         headers, rows = create_show
 | |
|       end
 | |
|       create_csv headers, rows, with_num?
 | |
|     end
 | |
| 
 | |
|   private
 | |
|     def create_list list, provider
 | |
|       abort(I18n.t("output.not_found.image.list")) if list.empty?
 | |
|       rows = []
 | |
|       headers = if provider
 | |
|         list.each {|l| rows.push [ l["name"], l["id"], l["status"] ]}
 | |
|         [
 | |
|           I18n.t("output.table_header.name"),
 | |
|           I18n.t("output.table_header.id"),
 | |
|           I18n.t("output.table_header.status")
 | |
|         ]
 | |
|       else
 | |
|         list.each {|l| rows.push  [ l["id"], l["name"], l["bootstrap_template"], l["remote_user"], l["provider"] ] }
 | |
|         [
 | |
|           I18n.t("output.table_header.id"),
 | |
|           I18n.t("output.table_header.name"),
 | |
|           I18n.t("output.table_header.template"),
 | |
|           I18n.t("output.table_header.remote_user"),
 | |
|           I18n.t("output.table_header.provider")
 | |
|         ]
 | |
|       end
 | |
|       return headers, rows
 | |
|     end
 | |
| 
 | |
|     def create_show
 | |
|       rows = [ [ @data["id"], @data["name"], @data["bootstrap_template"], @data["remote_user"], @data["provider"] ] ]
 | |
|       headers = [
 | |
|         I18n.t("output.table_header.id"),
 | |
|         I18n.t("output.table_header.name"),
 | |
|         I18n.t("output.table_header.template"),
 | |
|         I18n.t("output.table_header.remote_user"),
 | |
|         I18n.t("output.table_header.provider")
 | |
|       ]
 | |
|       return headers, rows
 | |
|     end
 | |
| 
 | |
|   end
 | |
| end
 | 
