class Pact::Headers
Public Class Methods
new(hash = {})
click to toggle source
# File lib/pact/consumer_contract/headers.rb, line 8 def initialize hash = {} hash.each_pair do | key, value | check_for_invalid key self[find_matching_key(key)] = value end self.freeze end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/pact/consumer_contract/headers.rb, line 16 def [] key super(find_matching_key(key)) end
fetch(*args, &block)
click to toggle source
Calls superclass method
# File lib/pact/consumer_contract/headers.rb, line 20 def fetch *args, &block args[0] = find_matching_key(args[0]) if args.first super(*args, &block) end
Private Instance Methods
check_for_invalid(key)
click to toggle source
# File lib/pact/consumer_contract/headers.rb, line 40 def check_for_invalid key unless (String === key || Symbol === key) raise InvalidHeaderNameTypeError.new "Header name (#{key}) must be a String or a Symbol." end if key? key raise DuplicateHeaderError.new "Duplicate header found (#{find_matching_key(key)} and #{key}. Please use a comma separated single value when multiple headers with the same name are required." end end
find_matching_key(key)
click to toggle source
# File lib/pact/consumer_contract/headers.rb, line 34 def find_matching_key key key = key.to_s match = keys.find { |k| k.downcase == key.downcase } match.nil? ? key : match end