Module: Useless::Doc::Server::Sinatra
- Defined in:
- lib/useless/doc/server/sinatra.rb
Overview
Provides access to the Doc::DSL
via the .doc
method. The JSON of the API doc that is built will be served via an OPTIONS request to the root. Resource documentation is similarly served via an OPTIONS request to the corresponding path.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.registered(app) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/useless/doc/server/sinatra.rb', line 57 def self.registered(app) app. '/' do if api = self.class.generated_doc last_modified api. Useless::Doc::Serialization::Dump.api(api) end end app. '/*' do if api = self.class.generated_doc resource = api.resources.find do |resource| resource.path == "/#{params[:splat].first}" end if resource last_modified api. return Useless::Doc::Serialization::Dump.resource(resource) end end pass end end |
Instance Method Details
#doc(name = nil, &block) ⇒ Object
47 48 49 50 51 |
# File 'lib/useless/doc/server/sinatra.rb', line 47 def doc(name = nil, &block) @dsl ||= Useless::Doc::DSL::API.new(name: name) @dsl.instance_eval(&block) if block_given? @dsl end |
#doc=(doc) ⇒ Object
43 44 45 |
# File 'lib/useless/doc/server/sinatra.rb', line 43 def doc=(doc) @doc = doc end |
#generated_doc ⇒ Object
53 54 55 |
# File 'lib/useless/doc/server/sinatra.rb', line 53 def generated_doc @doc ||= @dsl.generate if @dsl end |