Sha256: af68f15ca73443ae0bf16860969c1ace2978ac683b4d2bcdac9999b7b905c6fe

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'pact_broker/client/environments/environment_command'
require 'pact_broker/client/generate_display_name'
require 'yaml'

module PactBroker
  module Client
    module Environments
      class DescribeEnvironment < PactBroker::Client::Environments::EnvironmentCommand
        include PactBroker::Client::GenerateDisplayName
        private

        def do_call
          existing_environment_resource!
          PactBroker::Client::CommandResult.new(true, result_message)
        end

        def result_message
          if json_output?
            existing_environment_resource.response.raw_body
          else
            YAML.dump(displayify_keys(existing_environment_resource.response.body.except("_links"))).gsub("---\n", "")
          end
        end

        def 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-client-1.43.0 lib/pact_broker/client/environments/describe_environment.rb
pact_broker-client-1.42.0 lib/pact_broker/client/environments/describe_environment.rb