Class: Brainstem::ApiDocs::ControllerCollection

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

Instance Attribute Summary

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, #valid_options

Methods included from Concerns::Optional

#initialize, #valid_options

Constructor Details

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

Instance Method Details

#create_from_route(route) ⇒ Object

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



12
13
14
15
16
17
# File 'lib/brainstem/api_docs/controller_collection.rb', line 12

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

#find_by_route(route) ⇒ Object

Finds a controller from a route object.



23
24
25
26
27
# File 'lib/brainstem/api_docs/controller_collection.rb', line 23

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.



34
35
36
# File 'lib/brainstem/api_docs/controller_collection.rb', line 34

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