Module: DocMyRoutes::Annotatable
- Defined in:
- lib/doc_my_routes/doc/mixins/annotatable.rb
Overview
Logic to help with the REST API documentation. This module provides methods to “decorate” sinatra routes as follows:
summary 'Short definition of the route'
notes 'More detailed explanation of the operation'
status_codes [200, 401, 500]
get '/api/example' do
end
Class Method Summary collapse
-
.extended(mod) ⇒ Object
When a class is extended with this module documentation specific features are enabled.
Instance Method Summary collapse
-
#examples_regex(value) ⇒ Object
Match interaction examples to this route.
- #no_doc ⇒ Object
- #notes(value) ⇒ Object
-
#notes_ref(value) ⇒ Object
It’s possible to provide the route notes using a file to avoid adding too much text in the route definition.
- #produces(*value) ⇒ Object
- #route_documentation ⇒ Object
- #status_codes(value) ⇒ Object
- #summary(value) ⇒ Object
Class Method Details
.extended(mod) ⇒ Object
When a class is extended with this module documentation specific features are enabled
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 19 def extended(mod) # Wrap sinatra's route method to register the defined routes mod.define_singleton_method(:route) do |verb, route_pattern, conditions = {}, &block| result = super(verb, route_pattern, conditions, &block) track_route(self, verb, route_pattern, conditions) result end extract_url_map if Mapping.mapping_used? end |
Instance Method Details
#examples_regex(value) ⇒ Object
Match interaction examples to this route
81 82 83 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 81 def examples_regex(value) route_documentation.examples_regex = value end |
#no_doc ⇒ Object
60 61 62 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 60 def no_doc route_documentation.hidden = true end |
#notes(value) ⇒ Object
72 73 74 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 72 def notes(value) route_documentation.notes = value end |
#notes_ref(value) ⇒ Object
It’s possible to provide the route notes using a file to avoid adding too much text in the route definition
87 88 89 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 87 def notes_ref(value) route_documentation.notes_ref = value end |
#produces(*value) ⇒ Object
64 65 66 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 64 def produces(*value) route_documentation.produces = value end |
#route_documentation ⇒ Object
53 54 55 56 57 58 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 53 def route_documentation @route_documentation ||= begin DocMyRoutes.logger.debug 'Tracking new route' RouteDocumentation.new end end |
#status_codes(value) ⇒ Object
76 77 78 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 76 def status_codes(value) route_documentation.status_codes = value end |
#summary(value) ⇒ Object
68 69 70 |
# File 'lib/doc_my_routes/doc/mixins/annotatable.rb', line 68 def summary(value) route_documentation.summary = value end |