Sha256: b447875057b3fa98e80fcf83934d4ec4afe852e6312f737a5269375848babca8

Contents?: true

Size: 841 Bytes

Versions: 10

Compression:

Stored size: 841 Bytes

Contents

module RspecApiDocs
  class Resource
    class Example
      class RequestHeaders
        attr_reader :env

        def self.call(*args)
          new(*args).call
        end

        def initialize(env)
          @env = env
        end

        def call
          headers.reject do |k, v|
            excluded_headers.include?(k)
          end
        end

        private

        # http://stackoverflow.com/a/33235714/826820
        def headers
          Hash[
            *env.select { |k, v| k.start_with? 'HTTP_' }
            .collect { |k, v| [k.sub(/^HTTP_/, ''), v] }
            .collect { |k, v| [k.split('_').collect(&:capitalize).join('-'), v] }
            .sort.flatten
          ]
        end

        def excluded_headers
          RspecApiDocs.configuration.exclude_request_headers
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rspec-api-docs-1.1.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-1.0.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.14.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.13.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.12.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.11.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.10.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.9.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.8.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb
rspec-api-docs-0.7.0 lib/rspec_api_docs/formatter/resource/example/request_headers.rb