Skip to content

Commit

Permalink
fix: use refinement to add compact to Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 28, 2021
1 parent 7b8d0d7 commit c2c1cab
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/pact_broker/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
require 'pact_broker/client/version'
require 'pact_broker/client/backports'
require 'pact_broker/client/pact_broker_client'
5 changes: 4 additions & 1 deletion lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'pact_broker/client/cli/custom_thor'
require 'pact_broker/client/hash_refinements'
require 'thor/error'

module PactBroker
Expand All @@ -11,6 +12,8 @@ class AuthError < ::Thor::Error; end
class VersionCreationError < ::Thor::Error; end

class Broker < CustomThor
using PactBroker::Client::HashRefinements

desc 'can-i-deploy', ''
long_desc File.read(File.join(File.dirname(__FILE__), 'can_i_deploy_long_desc.txt'))

Expand Down Expand Up @@ -229,7 +232,7 @@ def validate_can_i_deploy_selectors selectors

def publish_pacts pact_files
require 'pact_broker/client/publish_pacts'
require 'pact_broker/client/backports'

write_options = options[:merge] ? { write: :merge } : {}
consumer_version_params = {
number: options.consumer_app_version,
Expand Down
4 changes: 3 additions & 1 deletion lib/pact_broker/client/git.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'pact_broker/client/error'
require 'pact_broker/client/backports'
require 'pact_broker/client/hash_refinements'

=begin
Expand All @@ -22,6 +22,8 @@
module PactBroker
module Client
module Git
using PactBroker::Client::HashRefinements

COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
COMMIT_ENV_VAR_NAMES = %w{BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
Expand Down
19 changes: 19 additions & 0 deletions lib/pact_broker/client/hash_refinements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module PactBroker
module Client
module HashRefinements
refine Hash do
def compact
h = {}
each do |key, value|
h[key] = value unless value == nil
end
h
end unless Hash.method_defined? :compact

def compact!
reject! {|_key, value| value == nil}
end unless Hash.method_defined? :compact!
end
end
end
end
3 changes: 2 additions & 1 deletion lib/pact_broker/client/matrix/text_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'table_print'
require 'dig_rb'
require 'pact_broker/client/backports'
require 'pact_broker/client/hash_refinements'

module PactBroker
module Client
class Matrix
class TextFormatter
using PactBroker::Client::HashRefinements

Line = Struct.new(:consumer, :consumer_version, :provider, :provider_version, :success, :ref)

Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/client/tasks/publication_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rake/tasklib'
require 'pact_broker/client/git'
require 'pact_broker/client/hash_refinements'

=begin
require pact_broker/client/tasks
Expand All @@ -17,6 +18,7 @@
module PactBroker
module Client
class PublicationTask < ::Rake::TaskLib
using PactBroker::Client::HashRefinements

attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
attr_reader :auto_detect_version_properties, :branch, :build_url
Expand Down Expand Up @@ -57,7 +59,6 @@ def rake_task &block
task task_name do
block.call(self)
require 'pact_broker/client/publish_pacts'
require 'pact_broker/client/backports'
pact_broker_client_options = { write: write_method, token: pact_broker_token }
pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
pact_broker_client_options.compact!
Expand Down

0 comments on commit c2c1cab

Please sign in to comment.