Class: ApiCanon::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/api_canon/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_path, controller_name, opts = {}) ⇒ Document

Returns a new instance of Document.



5
6
7
8
9
10
# File 'lib/api_canon/document.rb', line 5

def initialize(controller_path, controller_name, opts={})
  @controller_path = controller_path
  @controller_name = controller_name
  self.display_name = opts[:as]
  @documented_actions = []
end

Instance Attribute Details

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



3
4
5
# File 'lib/api_canon/document.rb', line 3

def controller_name
  @controller_name
end

#controller_pathObject (readonly)

Returns the value of attribute controller_path.



3
4
5
# File 'lib/api_canon/document.rb', line 3

def controller_path
  @controller_path
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/api_canon/document.rb', line 3

def description
  @description
end

#documented_actionsObject

Returns the value of attribute documented_actions.



4
5
6
# File 'lib/api_canon/document.rb', line 4

def documented_actions
  @documented_actions
end

Returns the value of attribute sidebar_link.



3
4
5
# File 'lib/api_canon/document.rb', line 3

def sidebar_link
  @sidebar_link
end

Instance Method Details

#add_action(documented_action) ⇒ Object



32
33
34
# File 'lib/api_canon/document.rb', line 32

def add_action(documented_action)
  @documented_actions << documented_action unless @documented_actions.map(&:action_name).include?(documented_action.action_name)
end

#describe(desc) ⇒ Object

The describe method is used as a DSL method in the document_controller block, use it to describe your API endpoint as a whole.

Parameters:

  • desc (String)

    The text to appear at the top of your API endpoint documentation page.

See Also:



15
16
17
# File 'lib/api_canon/document.rb', line 15

def describe(desc)
  @description = desc
end

#display_nameObject



21
22
23
# File 'lib/api_canon/document.rb', line 21

def display_name
  @display_name || @controller_name.titleize
end

#display_name=(dn) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/api_canon/document.rb', line 24

def display_name=(dn)
  if dn.nil?
    @display_name = nil
  else
    dn = dn.to_s
    @display_name = (dn =~ /\A([a-z]*|[A-Z]*)\Z/ ? dn.titleize : dn)
  end
end


18
19
20
# File 'lib/api_canon/document.rb', line 18

def link_path(link)
  @sidebar_link = link
end