Module: Pact::Reification

Includes:
ActiveSupportSupport
Defined in:
lib/pact/reification.rb

Class Method Summary collapse

Methods included from ActiveSupportSupport

#fix_all_the_things, #fix_json_formatting, #fix_regexp, #remove_unicode

Class Method Details

.escape(str) ⇒ Object



43
44
45
# File 'lib/pact/reification.rb', line 43

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

.from_term(term) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pact/reification.rb', line 13

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