Class: Brainstem::ApiDocs::ControllerCollection

Inherits:
AbstractCollection show all
Defined in:
lib/brainstem/api_docs/controller_collection.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractCollection

#atlas

Attributes included from Concerns::Formattable

#formatters

Instance Method Summary collapse

Methods inherited from AbstractCollection

#<<, #each, #each_filename, #each_formatted, #each_formatted_with_filename, #filenames, #formatted, #formatted_with_filename, #initialize, #last, with_members

Methods included from Concerns::Formattable

#formatted_as, #formatter_type

Methods included from Concerns::Optional

#initialize

Constructor Details

This class inherits a constructor from Brainstem::ApiDocs::AbstractCollection

Instance Attribute Details

#include_internalObject

Returns the value of attribute include_internal.



8
9
10
# File 'lib/brainstem/api_docs/controller_collection.rb', line 8

def include_internal
  @include_internal
end

Instance Method Details

#create_from_route(route) ⇒ Object

Creates a new controller from a route object and appends it to the collection.



19
20
21
22
23
24
25
# File 'lib/brainstem/api_docs/controller_collection.rb', line 19

def create_from_route(route)
  Controller.new(atlas,
    const:            route[:controller],
    name:             route[:controller_name].split("/").last,
    include_internal: include_internal
  ).tap { |controller| self.<< controller }
end

#find_by_route(route) ⇒ Object

Finds a controller from a route object.



30
31
32
33
34
# File 'lib/brainstem/api_docs/controller_collection.rb', line 30

def find_by_route(route)
  find do |controller|
    controller.const == route[:controller]
  end
end

#find_or_create_from_route(route) ⇒ Object Also known as: find_or_create_by_route

Finds a controller from a route object or creates one if it does not exist.



40
41
42
# File 'lib/brainstem/api_docs/controller_collection.rb', line 40

def find_or_create_from_route(route)
  find_by_route(route) || create_from_route(route)
end

#valid_optionsObject



10
11
12
13
14
# File 'lib/brainstem/api_docs/controller_collection.rb', line 10

def valid_options
  super | [
    :include_internal
  ]
end