Sha256: 87acd7c8c140a0ecc170c4363c3bd53c7948d80272c8aba8f4fb576ef47e47a6

Contents?: true

Size: 918 Bytes

Versions: 12

Compression:

Stored size: 918 Bytes

Contents

module Punchblock
  module HasHeaders
    ##
    # @return [Hash] hash of key-value pairs of headers
    #
    def headers_hash
      headers.inject({}) do |hash, header|
        hash[header.name] = header.value
        hash
      end
    end

    ##
    # @return [Array[Header]] headers
    #
    def headers
      find('//ns:header', :ns => self.class.registered_ns).map do |i|
        Header.new i
      end
    end

    ##
    # @param [Hash, Array] headers A hash of key-value header pairs, or an array of Header objects
    #
    def headers=(headers)
      find('//ns:header', :ns => self.class.registered_ns).each &:remove
      if headers.is_a? Hash
        headers.each_pair { |k,v| self << Header.new(k, v) }
      elsif headers.is_a? Array
        [headers].flatten.each { |i| self << Header.new(i) }
      end
    end

    def inspect_attributes # :nodoc:
      [:headers_hash] + super
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
punchblock-0.9.2 lib/punchblock/has_headers.rb
punchblock-0.9.1 lib/punchblock/has_headers.rb
punchblock-0.9.0 lib/punchblock/has_headers.rb
punchblock-0.8.4 lib/punchblock/has_headers.rb
punchblock-0.8.3 lib/punchblock/has_headers.rb
punchblock-0.8.2 lib/punchblock/has_headers.rb
punchblock-0.8.1 lib/punchblock/has_headers.rb
punchblock-0.8.0 lib/punchblock/has_headers.rb
punchblock-0.7.2 lib/punchblock/has_headers.rb
punchblock-0.7.1 lib/punchblock/has_headers.rb
punchblock-0.7.0 lib/punchblock/has_headers.rb
punchblock-0.6.2 lib/punchblock/has_headers.rb