class Rack::Spec::Docs
Constants
- DEFAULT_PATH
Public Class Methods
new(app, path: nil, schema: nil)
click to toggle source
Behaves as a rack-middleware @param app [Object] Rack
application @param path [String, nil] URL path to return document (default: /docs) @param schema [Hash] Schema
object written in JSON schema format
# File lib/rack/spec/docs.rb, line 10 def initialize(app, path: nil, schema: nil) @app = app @path = path @document = Jdoc::Generator.call(schema) end
Public Instance Methods
call(env)
click to toggle source
Returns rendered document for document request @param env [Hash] Rack
env
# File lib/rack/spec/docs.rb, line 18 def call(env) if env["REQUEST_METHOD"] == "GET" && env["PATH_INFO"] == path [ 200, { "Content-Type" => "text/plain; charset=utf-8" }, [@document], ] else @app.call(env) end end
Private Instance Methods
path()
click to toggle source
@return [String] Path to return document
# File lib/rack/spec/docs.rb, line 33 def path @path || DEFAULT_PATH end