Class: Rack::Swagger::JsonServer
- Inherits:
-
Object
- Object
- Rack::Swagger::JsonServer
- Includes:
- ServerHelpers
- Defined in:
- lib/rack/swagger/json_server.rb
Constant Summary collapse
- RESOURCE_DOC_JSON_MATCHER =
/^\/docs\/api-docs\/(.+)\/?/
- ROOT_DOC_JSON_MATCHER =
/^\/docs\/api-docs\/?/
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(docs_dir, opts) ⇒ JsonServer
constructor
A new instance of JsonServer.
Methods included from ServerHelpers
#base_path_value, #display_file, #display_file_or_404, #overwrite_base_path, #swagger_dist_path, #swagger_index_html_path
Constructor Details
#initialize(docs_dir, opts) ⇒ JsonServer
Returns a new instance of JsonServer.
9 10 11 12 |
# File 'lib/rack/swagger/json_server.rb', line 9 def initialize(docs_dir, opts) @docs_dir = docs_dir @opts = opts end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/swagger/json_server.rb', line 14 def call(env) case env['PATH_INFO'] when RESOURCE_DOC_JSON_MATCHER resource_doc = $1 display_file_or_404(:json, "#{@docs_dir}/#{resource_doc}.json", :resource) when ROOT_DOC_JSON_MATCHER display_file_or_404(:json, "#{@docs_dir}/swagger.json", :root) else [404, {}, ["Not found"]] end end |