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.17.0.pre.rc1 lib/pact/shared/form_differ.rb
pact-support-1.16.1 lib/pact/shared/form_differ.rb
pact-support-1.16.0 lib/pact/shared/form_differ.rb
pact-support-1.15.5 lib/pact/shared/form_differ.rb
pact-support-1.15.4 lib/pact/shared/form_differ.rb
pact-support-1.15.3 lib/pact/shared/form_differ.rb
pact-support-1.15.2 lib/pact/shared/form_differ.rb
pact-support-1.15.1 lib/pact/shared/form_differ.rb
pact-support-1.15.0 lib/pact/shared/form_differ.rb
pact-support-1.14.3 lib/pact/shared/form_differ.rb
pact-support-1.14.2 lib/pact/shared/form_differ.rb
pact-support-1.14.1 lib/pact/shared/form_differ.rb
pact-support-1.14.0 lib/pact/shared/form_differ.rb
pact-support-1.13.0 lib/pact/shared/form_differ.rb
pact-support-1.12.1 lib/pact/shared/form_differ.rb
pact-support-1.12.0 lib/pact/shared/form_differ.rb
pact-support-1.11.0 lib/pact/shared/form_differ.rb
pact-support-1.10.3 lib/pact/shared/form_differ.rb
pact-support-1.10.2 lib/pact/shared/form_differ.rb
pact-support-1.10.1 lib/pact/shared/form_differ.rb