Sha256: 62d79ebe41a2301d69293c5c3f78631ea4a3ede663cd5b9f9ea3f2e4c83cb52a
Contents?: true
Size: 1.05 KB
Versions: 5
Compression:
Stored size: 1.05 KB
Contents
module Raddocs # Rack middleware # # This lets you cURL for documentation. # # curl -H "Accept: text/docs+plain" http://localhost/orders # # This will return all of the docs for a given resource, "orders." It is returned # as a giant flat file containing all of the documentation. "combined_text" output # must be selected in `rspec_api_documentation`. # # The route matches the folder structure of the docs. class Middleware def initialize(app) @app = app @file_server = Rack::File.new(Raddocs.configuration.docs_dir) end def call(env) if env["HTTP_ACCEPT"] =~ Raddocs.configuration.docs_mime_type env = env.merge({ "PATH_INFO" => File.join(env["PATH_INFO"], "index.txt") }) response = @file_server.call(env) if response[0] == 404 body = "Docs are not available for this resource.\n" response = [404, {"Content-Type" => "type/plain", "Content-Length" => body.size.to_s}, [body]] end response else @app.call(env) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems