Class: ApiCanon::Document

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
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.



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

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

Instance Attribute Details

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



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

def controller_name
  @controller_name
end

#controller_pathObject (readonly)

Returns the value of attribute controller_path.



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

def controller_path
  @controller_path
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#documented_actionsObject

Returns the value of attribute documented_actions.



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

def documented_actions
  @documented_actions
end

#documented_modelsObject

Returns the value of attribute documented_models.



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

def documented_models
  @documented_models
end

Returns the value of attribute sidebar_link.



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

def sidebar_link
  @sidebar_link
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#add_action(documented_action) ⇒ Object



35
36
37
# File 'lib/api_canon/document.rb', line 35

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

#add_model(documented_model) ⇒ Object



38
39
40
# File 'lib/api_canon/document.rb', line 38

def add_model(documented_model)
  @documented_models[documented_model.id] = documented_model
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:



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

def describe(desc)
  @description = desc
end

#display_nameObject



24
25
26
# File 'lib/api_canon/document.rb', line 24

def display_name
  @display_name || @controller_name.titleize
end

#display_name=(dn) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/api_canon/document.rb', line 27

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


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

def link_path(link)
  @sidebar_link = link
end