From c0c3ad5a92ab02ac0de00d2b0a0d7afeb88095ce Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 16 Feb 2018 11:46:35 +1100 Subject: [PATCH] feat(message contracts): dynamically mix in new and from_hash into Pact::Message --- lib/pact/consumer_contract/message.rb | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/pact/consumer_contract/message.rb b/lib/pact/consumer_contract/message.rb index ca4fb28..faab269 100644 --- a/lib/pact/consumer_contract/message.rb +++ b/lib/pact/consumer_contract/message.rb @@ -44,7 +44,6 @@ def as_json } end - def request @request ||= Pact::Consumer::Request::Actual.from_hash( path: '/', @@ -115,8 +114,30 @@ def to_s end end -module Pact::Message - def self.new *args - Pact::ConsumerContract::Message.new(*args) +if Pact.const_defined?('Message') && Pact::Message.class == Module + module Pact + module Message + def self.new *args + Pact::ConsumerContract::Message.new(*args) + end + + def self.from_hash *args + Pact::ConsumerContract::Message.from_hash(*args) + end + end + end +end + +if Pact.const_defined?('Message') && Pact::Message.class == Class + module Pact + class Message + def self.new *args + Pact::ConsumerContract::Message.new(*args) + end + + def self.from_hash *args + Pact::ConsumerContract::Message.from_hash(*args) + end + end end end