Class: RailsApiDocs::Doc::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-api-docs/doc/responder.rb

Overview

Pure-Ruby responder that decides what to serve at /rails/api-docs. Sits between the Rails controller and the Renderer so that the decision logic (file present? render fresh; file missing? show setup page) can be unit-tested without booting a Rails app.

Instance Method Summary collapse

Constructor Details

#initialize(config_path:) ⇒ Responder

Returns a new instance of Responder.



10
11
12
# File 'lib/rails-api-docs/doc/responder.rb', line 10

def initialize(config_path:)
  @config_path = config_path
end

Instance Method Details

#renderObject

Returns [status, html_string].



15
16
17
18
19
20
21
22
# File 'lib/rails-api-docs/doc/responder.rb', line 15

def render
  if File.exist?(@config_path)
    html = Doc::Renderer.new(Config::Loader.load(@config_path)).call
    [200, html]
  else
    [404, missing_config_page]
  end
end