Class: Brainstem::ApiDocs::Controller

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Concerns::Formattable, Concerns::Optional
Defined in:
lib/brainstem/api_docs/controller.rb

Instance Attribute Summary collapse

Attributes included from Concerns::Formattable

#formatters

Instance Method Summary collapse

Methods included from Concerns::Formattable

#formatted_as, #formatter_type

Constructor Details

#initialize(atlas, options = {}) {|_self| ... } ⇒ Controller

Returns a new instance of Controller.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
# File 'lib/brainstem/api_docs/controller.rb', line 14

def initialize(atlas, options = {})
  self.atlas     = atlas
  self.endpoints = EndpointCollection.new(atlas)
  super options
  yield self if block_given?
end

Instance Attribute Details

#atlasObject

Returns the value of attribute atlas.



21
22
23
# File 'lib/brainstem/api_docs/controller.rb', line 21

def atlas
  @atlas
end

#constObject

Returns the value of attribute const.



21
22
23
# File 'lib/brainstem/api_docs/controller.rb', line 21

def const
  @const
end

#endpointsObject

Returns the value of attribute endpoints.



21
22
23
# File 'lib/brainstem/api_docs/controller.rb', line 21

def endpoints
  @endpoints
end


68
69
70
# File 'lib/brainstem/api_docs/controller.rb', line 68

def filename_link_pattern
  @filename_link_pattern ||= Brainstem::ApiDocs.controller_filename_link_pattern
end

#filename_patternObject

Returns the value of attribute filename_pattern.



21
22
23
# File 'lib/brainstem/api_docs/controller.rb', line 21

def filename_pattern
  @filename_pattern
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/brainstem/api_docs/controller.rb', line 21

def name
  @name
end

Instance Method Details

#add_endpoint(endpoint) ⇒ Object

Adds an existing endpoint to its endpoint collection.



43
44
45
# File 'lib/brainstem/api_docs/controller.rb', line 43

def add_endpoint(endpoint)
  self.endpoints << endpoint
end

#contextual_documentation(key) ⇒ Object

Returns a key if it exists and is documentable.



102
103
104
105
106
# File 'lib/brainstem/api_docs/controller.rb', line 102

def contextual_documentation(key)
  default_configuration.has_key?(key) &&
    !default_configuration[key][:nodoc] &&
    default_configuration[key][:info]
end

#default_configurationObject



75
76
77
# File 'lib/brainstem/api_docs/controller.rb', line 75

def default_configuration
  configuration[:_default]
end

#descriptionObject



87
88
89
# File 'lib/brainstem/api_docs/controller.rb', line 87

def description
  contextual_documentation(:description) || ""
end

#extensionObject



60
61
62
# File 'lib/brainstem/api_docs/controller.rb', line 60

def extension
  @extension ||= Brainstem::ApiDocs.output_extension
end

#nodoc?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/brainstem/api_docs/controller.rb', line 79

def nodoc?
  default_configuration[:nodoc]
end

#suggested_filename(format) ⇒ Object



47
48
49
50
51
52
# File 'lib/brainstem/api_docs/controller.rb', line 47

def suggested_filename(format)
  filename_pattern
    .gsub('{{namespace}}', const.to_s.deconstantize.underscore)
    .gsub('{{name}}', name.to_s.split("/").last)
    .gsub('{{extension}}', extension)
end


54
55
56
57
58
# File 'lib/brainstem/api_docs/controller.rb', line 54

def suggested_filename_link(format)
  filename_link_pattern
    .gsub('{{name}}', name.to_s)
    .gsub('{{extension}}', extension)
end

#tagObject



91
92
93
# File 'lib/brainstem/api_docs/controller.rb', line 91

def tag
  default_configuration[:tag]
end

#tag_groupsObject



95
96
97
# File 'lib/brainstem/api_docs/controller.rb', line 95

def tag_groups
  default_configuration[:tag_groups]
end

#titleObject



83
84
85
# File 'lib/brainstem/api_docs/controller.rb', line 83

def title
  contextual_documentation(:title) || const.to_s.demodulize
end

#valid_optionsObject



30
31
32
33
34
35
36
37
38
# File 'lib/brainstem/api_docs/controller.rb', line 30

def valid_options
  super | [
    :const,
    :name,
    :formatters,
    :filename_pattern,
    :filename_link_pattern
  ]
end

#valid_sorted_endpointsObject



108
109
110
# File 'lib/brainstem/api_docs/controller.rb', line 108

def valid_sorted_endpoints
  endpoints.sorted_with_actions_in_controller(const)
end