Module: Useless::Doc::Sinatra

Defined in:
lib/useless/doc/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#doc(path, &block) ⇒ Object

Provides access to the Doc::DSL. The JSON of the resource that is created will then be served via an OPTIONS request to the specified path.

Examples:

class ResourceApp < Sinatra::Base
  register Useless::Doc::Sinatra

  doc '/some-resources' do
    get 'Get all of these resources' do
      request do
        parameter 'page', 'The page of resources to return.'
      end

      response do
        body do
          attribute 'name', 'The name of the resource.'
        end
      end
    end
  end
end

Parameters:

  • path (String)

    the path of the resource to be documented.

  • block

    is passed to the DSL to build the resource.



37
38
39
40
41
42
43
# File 'lib/useless/doc/sinatra.rb', line 37

def doc(path, &block)
  resource = Useless::Doc::DSL::Resource.build path: path, &block

  options(path) do
    Doc::Serialization::Dump.resource(resource)
  end
end