Sha256: 90684d6e4e874cf44127e5b53684c483d09fa1b736a55c3116f602beff93faab

Contents?: true

Size: 960 Bytes

Versions: 18

Compression:

Stored size: 960 Bytes

Contents

require 'randexp'
require 'rack/utils'
# reqiore 'active_support/core_ext/object/to_param'
module Pact
  module Reification
    include ActiveSupportSupport

    def self.from_term(term)
      case term
      when Pact::Term, Regexp, Pact::SomethingLike
      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}=#{from_term(x)}"}.join('&')
          else
            "#{k}=#{from_term(v)}"
          end
        }.join('&')
      else
        term
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pact-support-0.5.1 lib/pact/reification.rb
pact-support-0.5.0 lib/pact/reification.rb
pact-support-0.4.4 lib/pact/reification.rb
pact-support-0.4.3 lib/pact/reification.rb
pact-support-0.4.2 lib/pact/reification.rb
pact-support-0.4.1 lib/pact/reification.rb
pact-support-0.4.0 lib/pact/reification.rb
pact-support-0.3.1 lib/pact/reification.rb
pact-support-0.3.0 lib/pact/reification.rb
pact-support-0.2.1 lib/pact/reification.rb
pact-support-0.1.4 lib/pact/reification.rb
pact-support-0.2.0 lib/pact/reification.rb
pact-support-0.1.3 lib/pact/reification.rb
pact-support-0.1.2 lib/pact/reification.rb
pact-support-0.1.1 lib/pact/reification.rb
pact-support-0.1.0 lib/pact/reification.rb
pact-support-0.0.4 lib/pact/reification.rb
pact-support-0.0.3 lib/pact/reification.rb