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


70
71
72
# File 'lib/brainstem/api_docs/controller.rb', line 70

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

#include_internalObject

Returns the value of attribute include_internal.



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

def include_internal
  @include_internal
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.



45
46
47
# File 'lib/brainstem/api_docs/controller.rb', line 45

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

#contextual_documentation(key) ⇒ Object

Returns a key if it exists and is documentable.



104
105
106
107
108
# File 'lib/brainstem/api_docs/controller.rb', line 104

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

#default_configurationObject



77
78
79
# File 'lib/brainstem/api_docs/controller.rb', line 77

def default_configuration
  configuration[:_default]
end

#descriptionObject



89
90
91
# File 'lib/brainstem/api_docs/controller.rb', line 89

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

#extensionObject



62
63
64
# File 'lib/brainstem/api_docs/controller.rb', line 62

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

#nodoc?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/brainstem/api_docs/controller.rb', line 81

def nodoc?
  nodoc_for?(default_configuration)
end

#suggested_filename(format) ⇒ Object



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

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


56
57
58
59
60
# File 'lib/brainstem/api_docs/controller.rb', line 56

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

#tagObject



93
94
95
# File 'lib/brainstem/api_docs/controller.rb', line 93

def tag
  default_configuration[:tag]
end

#tag_groupsObject



97
98
99
# File 'lib/brainstem/api_docs/controller.rb', line 97

def tag_groups
  default_configuration[:tag_groups]
end

#titleObject



85
86
87
# File 'lib/brainstem/api_docs/controller.rb', line 85

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

#valid_optionsObject



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

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

#valid_sorted_endpointsObject



110
111
112
# File 'lib/brainstem/api_docs/controller.rb', line 110

def valid_sorted_endpoints
  endpoints.sorted_with_actions_in_controller(const)
end