Sha256: f27d3ea4d3098dc2b9ef5bcc7882c367bd4f28c572f910636bf232f7aaf12f2f

Contents?: true

Size: 802 Bytes

Versions: 8

Compression:

Stored size: 802 Bytes

Contents

require 'rack/request'

module Useless
  module Doc
    class Proxy

      # +Doc::Proxy::URL+ translates the request URL into the corresponding
      # API URL using the specified 'useless.doc.router'.
      #
      class URL
        def initialize(app)
          @app = app
        end

        def call(env)
          request = ::Rack::Request.new(env)

          if url = env['useless.doc.router'].api_for_doc(request.url)
            env['useless.doc.url'] = url

            if env['useless.doc.logger']
              env['useless.doc.logger'].info "routing #{request.url} to #{env['useless.doc.url']}"
            end

            @app.call(env)
          else
            [404, {'Content-Type' => 'text/plain'}, ['Unknown documentation.']]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
useless-doc-0.7.0 lib/useless/doc/proxy/url.rb
useless-doc-0.6.5 lib/useless/doc/proxy/url.rb
useless-doc-0.6.4 lib/useless/doc/proxy/url.rb
useless-doc-0.6.3 lib/useless/doc/proxy/url.rb
useless-doc-0.6.2 lib/useless/doc/proxy/url.rb
useless-doc-0.6.1 lib/useless/doc/proxy/url.rb
useless-doc-0.6.0 lib/useless/doc/proxy/url.rb
useless-doc-0.5.0 lib/useless/doc/proxy/url.rb