-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add describe-environment command
- Loading branch information
Showing
4 changed files
with
68 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'yaml' | ||
require 'pact_broker/client/generate_display_name' | ||
|
||
module PactBroker | ||
module Client | ||
class DescribeTextFormatter | ||
extend GenerateDisplayName | ||
|
||
def self.call(properties) | ||
YAML.dump(displayify_keys(properties)).gsub("---\n", "") | ||
end | ||
|
||
def self.displayify_keys(thing) | ||
case thing | ||
when Hash then thing.each_with_object({}) { | (key, value), new_hash | new_hash[generate_display_name(key)] = displayify_keys(value) } | ||
when Array then thing.collect{ | value | displayify_keys(value) } | ||
else | ||
thing | ||
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
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,33 @@ | ||
require 'pact_broker/client/base_command' | ||
require 'pact_broker/client/describe_text_formatter' | ||
|
||
module PactBroker | ||
module Client | ||
module Pacticipants2 | ||
class Describe < PactBroker::Client::BaseCommand | ||
|
||
private | ||
|
||
def do_call | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def pacticipant_entity | ||
@pacticipant_entity ||= index_resource._link('pb:pacticipant').expand('pacticipant' => params[:name]).get! | ||
end | ||
|
||
def result_message | ||
if json_output? | ||
pacticipant_entity.response.raw_body | ||
else | ||
properties = pacticipant_entity.response.body.except("_links", "_embedded") | ||
if pacticipant_entity._embedded["labels"] && pacticipant_entity._embedded["labels"].any? | ||
properties["labels"] = pacticipant_entity._embedded["labels"] | ||
end | ||
PactBroker::Client::DescribeTextFormatter.call(properties) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |