Module: ApiCanon::ClassMethods

Defined in:
lib/api_canon.rb

Instance Method Summary collapse

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

See Also:



64
65
66
67
68
69
# File 'lib/api_canon.rb', line 64

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


85
86
87
88
89
90
91
92
# File 'lib/api_canon.rb', line 85

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, controller_name
  documented_action.instance_eval &block if block_given?
  document.add_action documented_action
  DocumentationStore.store document
end