Sha256: f305f6de1468f0a7dd07c80753ea26db6a8e4ca6e2538af33d3e21791e9521aa

Contents?: true

Size: 780 Bytes

Versions: 60

Compression:

Stored size: 780 Bytes

Contents

require 'uri'

module Pact
  class FormDiffer

    def self.call expected, actual, options = {}
      require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
      ::Pact::Matchers.diff to_hash(expected), to_hash(actual), options
    end

    def self.to_hash form_body
      if form_body.is_a?(Hash)
        ensure_values_are_arrays form_body
      else
        decode_www_form form_body
      end
    end

    def self.ensure_values_are_arrays hash
      hash.each_with_object({}) do | (key, value), h |
        h[key.to_s] = [*value]
      end
    end

    def self.decode_www_form string
      URI.decode_www_form(string).each_with_object({}) do | (key, value), hash |
        hash[key] ||= []
        hash[key] << value
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 2 rubygems

Version Path
pact-support-1.21.1 lib/pact/shared/form_differ.rb
pact-support-1.21.0 lib/pact/shared/form_differ.rb
pact-support-1.20.2 lib/pact/shared/form_differ.rb
pact-support-1.20.1 lib/pact/shared/form_differ.rb
pact-support-1.20.0 lib/pact/shared/form_differ.rb
pact-support-1.19.0 lib/pact/shared/form_differ.rb
pact-support-1.18.1 lib/pact/shared/form_differ.rb
pact-support-1.18.0 lib/pact/shared/form_differ.rb
hs-pact-support-1.17.1 lib/pact/shared/form_differ.rb
pact-support-1.17.0 lib/pact/shared/form_differ.rb
pact-support-1.16.10 lib/pact/shared/form_differ.rb
pact-support-1.16.9 lib/pact/shared/form_differ.rb
pact-support-1.16.8 lib/pact/shared/form_differ.rb
pact-support-1.16.7 lib/pact/shared/form_differ.rb
pact-support-1.16.6 lib/pact/shared/form_differ.rb
pact-support-1.16.5 lib/pact/shared/form_differ.rb
pact-support-1.16.4 lib/pact/shared/form_differ.rb
pact-support-1.16.3 lib/pact/shared/form_differ.rb
pact-support-1.16.2 lib/pact/shared/form_differ.rb
pact-support-1.17.0.pre.rc2 lib/pact/shared/form_differ.rb