Sha256: 2e28b6cb1e9779fb4196ef5364f55595e32c6a039c44c6b7e3bfc0c4230b7bf9

Contents?: true

Size: 1.28 KB

Versions: 34

Compression:

Stored size: 1.28 KB

Contents

require 'randexp'
require 'pact/term'
require 'pact/something_like'
require 'pact/array_like'
require 'pact/shared/request'
require 'pact/consumer_contract/query_hash'
require 'pact/consumer_contract/query_string'
require 'pact/consumer_contract/string_with_matching_rules'

module Pact
  module Reification
    include ActiveSupportSupport

    def self.from_term(term)
      case term
      when Pact::Term, Regexp, Pact::SomethingLike, Pact::ArrayLike
        from_term(term.generate)
      when Hash
        term.inject({}) do |mem, (key,t)|
          mem[key] = from_term(t)
          mem
        end
      when Array
        term.map{ |t| from_term(t)}
      when Pact::Request::Base
        from_term(term.to_hash)
      when Pact::QueryString
        from_term(term.query)
      when Pact::QueryHash
        from_term(term.query).map { |k, v|
          if v.nil?
            k
          elsif v.is_a?(Array) #For cases where there are multiple instance of the same parameter
            v.map { |x| "#{k}=#{escape(x)}"}.join('&')
          else
            "#{k}=#{escape(v)}"
          end
        }.join('&')
      when Pact::StringWithMatchingRules
        String.new(term)
      else
        term
      end
    end

    def self.escape(str)
      URI.encode_www_form_component(str)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
pact-support-1.16.4 lib/pact/reification.rb
pact-support-1.16.3 lib/pact/reification.rb
pact-support-1.16.2 lib/pact/reification.rb
pact-support-1.17.0.pre.rc2 lib/pact/reification.rb
pact-support-1.17.0.pre.rc1 lib/pact/reification.rb
pact-support-1.16.1 lib/pact/reification.rb
pact-support-1.16.0 lib/pact/reification.rb
pact-support-1.15.5 lib/pact/reification.rb
pact-support-1.15.4 lib/pact/reification.rb
pact-support-1.15.3 lib/pact/reification.rb
pact-support-1.15.2 lib/pact/reification.rb
pact-support-1.15.1 lib/pact/reification.rb
pact-support-1.15.0 lib/pact/reification.rb
pact-support-1.14.3 lib/pact/reification.rb
pact-support-1.14.2 lib/pact/reification.rb
pact-support-1.14.1 lib/pact/reification.rb
pact-support-1.14.0 lib/pact/reification.rb
pact-support-1.13.0 lib/pact/reification.rb
pact-support-1.12.1 lib/pact/reification.rb
pact-support-1.12.0 lib/pact/reification.rb