forked from pact-foundation/pact_broker-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'pact_broker/client/base_command' | ||
require 'pact_broker/client/pacticipants/text_formatter' | ||
|
||
module PactBroker | ||
module Client | ||
module Pacticipants2 | ||
class List < PactBroker::Client::BaseCommand | ||
private | ||
|
||
attr_reader :environments_resource | ||
|
||
def do_call | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def environments_resource | ||
@environments_resource = environments_link.get! | ||
end | ||
|
||
def environments_link | ||
index_resource._link!('pb:pacticipants') | ||
end | ||
|
||
def result_message | ||
if json_output? | ||
environments_resource.response.raw_body | ||
else | ||
TextFormatter.call(environments_resource._embedded["pacticipants"]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'table_print' | ||
require 'ostruct' | ||
|
||
module PactBroker | ||
module Client | ||
module Pacticipants2 | ||
class TextFormatter | ||
def self.call(pacticipants) | ||
return "" if pacticipants.size == 0 | ||
|
||
data = pacticipants.collect do | pacticipant | | ||
# Might add a UUID in at some stage. Backwards compatible supporting code. | ||
OpenStruct.new({ uuid: "" }.merge(pacticipant).merge(url: pacticipant["_links"]["self"]["href"])) | ||
end.sort_by{ | pacticipant | pacticipant.name.downcase } | ||
|
||
uuid_width = max_width(data, :uuid) | ||
name_width = max_width(data, :name) | ||
display_name_width = max_width(data, :display_name) | ||
|
||
tp_options = [ | ||
{ name: { width: name_width} }, | ||
{ displayName: { display_name: "Display name", width: display_name_width } }, | ||
] | ||
|
||
if uuid_width > 0 | ||
tp_options.unshift({ uuid: { width: uuid_width } }) | ||
end | ||
|
||
TablePrint::Printer.new(data, tp_options).table_print | ||
end | ||
|
||
def self.max_width(data, column) | ||
data.collect{ |row| row.send(column) }.compact.collect(&:size).max | ||
end | ||
end | ||
end | ||
end | ||
end |