Class: Brainstem::ApiDocs::ControllerCollection
- Inherits:
-
AbstractCollection
- Object
- AbstractCollection
- Brainstem::ApiDocs::ControllerCollection
- Defined in:
- lib/brainstem/api_docs/controller_collection.rb
Instance Attribute Summary
Attributes inherited from AbstractCollection
Attributes included from Concerns::Formattable
Instance Method Summary collapse
-
#create_from_route(route) ⇒ Object
Creates a new controller from a route object and appends it to the collection.
-
#find_by_route(route) ⇒ Object
Finds a controller from a route object.
-
#find_or_create_from_route(route) ⇒ Object
(also: #find_or_create_by_route)
Finds a controller from a route object or creates one if it does not exist.
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
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.
11 12 13 14 15 16 |
# File 'lib/brainstem/api_docs/controller_collection.rb', line 11 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.
21 22 23 24 25 |
# File 'lib/brainstem/api_docs/controller_collection.rb', line 21 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.
31 32 33 |
# File 'lib/brainstem/api_docs/controller_collection.rb', line 31 def find_or_create_from_route(route) find_by_route(route) || create_from_route(route) end |