Module: ApiCanon::ClassMethods
- Defined in:
- lib/api_canon.rb
Instance Method Summary collapse
-
#document_controller(opts = {}, &block) ⇒ Object
document_controller is used to describe your controller as a whole (Your API endpoint).
-
#document_method(method_name, &block) ⇒ Object
document_method is used to describe the actions in your controller (your API actions).
Instance Method Details
#document_controller(opts = {}, &block) ⇒ Object
document_controller is used to describe your controller as a whole (Your API endpoint)
Example:
document_controller as: 'Awesome Things' do
describe "Here you can see all the awesome things, and get more details about the awesome things you're interested in."
end
50 51 52 53 54 55 |
# File 'lib/api_canon.rb', line 50 def document_controller(opts={}, &block) document = DocumentationStore.fetch controller_path document ||= Document.new controller_path, controller_name, opts document.instance_eval &block if block_given? DocumentationStore.store document end |
#document_method(method_name, &block) ⇒ Object
document_method is used to describe the actions in your controller (your API actions)
Example:
document_method :index do
describe "Gives you a list of awesome things!"
param :foo, type: 'String', default: 'bar', example_values: Foo.limit(5).pluck(:name), description: 'foo is the type of awesome required'
param :filter_level, type: 'Integer', default: 1, values: [1,2,3,4], description: 'filter_level can only be 1, 2, 3 or 4'
end
71 72 73 74 75 76 77 78 |
# File 'lib/api_canon.rb', line 71 def document_method(method_name,&block) document = DocumentationStore.fetch controller_path document ||= Document.new controller_path, controller_name documented_action = ApiCanon::DocumentedAction.new method_name documented_action.instance_eval &block if block_given? document.add_action documented_action DocumentationStore.store document end |