fluke/devops-client/lib/devops-client/output/role.rb
Tim Lianov 03dc3d8d99 v3
2018-04-04 22:44:39 +03:00

76 lines
2.1 KiB
Ruby

require "devops-client/output/base"
module Output
class Role < Base
def table
title, headers, rows = nil, nil, nil
case options[:current_command]
when :list
headers, rows = prepare_list
title = "output.title.role.list"
when :show
headers, rows = prepare_show
title = "output.title.role.show"
when :policies
headers, rows = prepare_policies
title = "output.title.role.policies"
end
create_table headers, rows, I18n.t(title)
end
def csv
headers, rows = nil, nil
case options[:current_command]
when :list
headers, rows = prepare_list
when :show
headers, rows = prepare_show
when :policies
headers, rows = prepare_policies
end
create_csv headers, rows
end
private
def prepare_list
headers = [
I18n.t("output.table_header.id"),
I18n.t("output.table_header.name"),
I18n.t("output.table_header.description"),
I18n.t("output.table_header.policies"),
I18n.t("output.table_header.created_at")
]
rows = @data.map do |role|
[ role["id"], role["name"], role["description"], role["policies"], time_to_s(role["created_at"]) ]
end
return headers, rows
end
def prepare_show
headers = [
I18n.t("output.table_header.id"),
I18n.t("output.table_header.name"),
I18n.t("output.table_header.description"),
I18n.t("output.table_header.policies"),
I18n.t("output.table_header.created_at")
]
rows = [[ @data["id"], @data["name"], @data["description"], @data["policies"], time_to_s(@data["created_at"]) ]]
return headers, rows
end
def prepare_policies
headers = [
I18n.t("output.table_header.id"),
I18n.t("output.table_header.description"),
I18n.t("output.table_header.dependencies")
]
rows = @data.map do |policy|
[ policy["id"], policy["description"], policy["dependencies"] ]
end
return headers, rows
end
end
end