Class: Brainstem::ApiDocs::EndpointCollection

Inherits:
AbstractCollection show all
Includes:
Concerns::Formattable
Defined in:
lib/brainstem/api_docs/endpoint_collection.rb

Instance Attribute Summary

Attributes included from Concerns::Formattable

#formatters

Attributes inherited from AbstractCollection

#atlas

Instance Method Summary collapse

Methods included from Concerns::Formattable

#formatted_as, #formatter_type, #valid_options

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::Optional

#initialize, #valid_options

Constructor Details

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

Instance Method Details

#create_from_route(route, controller) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/brainstem/api_docs/endpoint_collection.rb', line 22

def create_from_route(route, controller)
  Endpoint.new(atlas) do |ep|
    ep.path             = route[:path]
    ep.http_methods     = route[:http_methods]
    ep.controller       = controller
    ep.controller_name  = route[:controller_name]
    ep.action           = route[:action]
  end.tap { |endpoint| self.<< endpoint }
end

#find_from_route(route) ⇒ Object Also known as: find_by_route



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

def find_from_route(route)
  find do |endpoint|
    endpoint.path == route[:path] &&
      endpoint.controller.const == route[:controller] &&
      endpoint.action == route[:action]
  end
end

#only_documentableObject



33
34
35
# File 'lib/brainstem/api_docs/endpoint_collection.rb', line 33

def only_documentable
  self.class.with_members(atlas, reject(&:nodoc?))
end

#sortedObject



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

def sorted
  self.class.with_members(atlas, sort)
end

#sorted_with_actions_in_controller(const) ⇒ Object



53
54
55
# File 'lib/brainstem/api_docs/endpoint_collection.rb', line 53

def sorted_with_actions_in_controller(const)
  with_actions_in_controller(const).sorted
end

#with_actions_in_controller(const) ⇒ Object



48
49
50
# File 'lib/brainstem/api_docs/endpoint_collection.rb', line 48

def with_actions_in_controller(const)
  self.class.with_members(atlas, reject { |m| !const.method_defined?(m.action) })
end

#with_declared_presented_classObject



38
39
40
# File 'lib/brainstem/api_docs/endpoint_collection.rb', line 38

def with_declared_presented_class
  self.class.with_members(atlas, reject { |m| m.declared_presented_class.nil? })
end