Sha256: 007adef2baebc79a252e0afde8d6eb7d108cc1b6f4ae2549f37a1e822db3e552

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

require 'randexp'
require 'rack/utils'
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'

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,term)|
          mem[key] = from_term(term)
          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
        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(from_term(x))}"}.join('&')
          else
            "#{k}=#{escape(from_term(v))}"
          end
        }.join('&')
      else
        term
      end
    end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pact-support-1.2.3 lib/pact/reification.rb
pact-support-1.2.2 lib/pact/reification.rb
pact-support-1.2.1 lib/pact/reification.rb
pact-support-1.2.0 lib/pact/reification.rb
pact-support-1.1.8 lib/pact/reification.rb
pact-support-1.1.7 lib/pact/reification.rb
pact-support-1.1.6 lib/pact/reification.rb
pact-support-1.1.5 lib/pact/reification.rb
pact-support-1.1.4 lib/pact/reification.rb
pact-support-1.1.3 lib/pact/reification.rb
pact-support-1.1.2 lib/pact/reification.rb