Sha256: e0d47fae5ad3e8469e821dd762714b12c9e2c37a62a9983a29b90c91d7dc1c9b

Contents?: true

Size: 938 Bytes

Versions: 13

Compression:

Stored size: 938 Bytes

Contents

# encoding: utf-8

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

13 entries across 13 versions & 1 rubygems

Version Path
punchblock-1.5.3 lib/punchblock/has_headers.rb
punchblock-1.5.2 lib/punchblock/has_headers.rb
punchblock-1.5.1 lib/punchblock/has_headers.rb
punchblock-1.5.0 lib/punchblock/has_headers.rb
punchblock-1.4.1 lib/punchblock/has_headers.rb
punchblock-1.4.0 lib/punchblock/has_headers.rb
punchblock-1.3.0 lib/punchblock/has_headers.rb
punchblock-1.2.0 lib/punchblock/has_headers.rb
punchblock-1.1.0 lib/punchblock/has_headers.rb
punchblock-1.0.0 lib/punchblock/has_headers.rb
punchblock-0.12.0 lib/punchblock/has_headers.rb
punchblock-0.11.0 lib/punchblock/has_headers.rb
punchblock-0.10.0 lib/punchblock/has_headers.rb