Class: Minitest::Apidoc::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/apidoc/group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, endpoints) ⇒ Group

Returns a new instance of Group


6
7
8
9
# File 'lib/minitest/apidoc/group.rb', line 6

def initialize(name, endpoints)
  @name = name || ""
  @endpoints = endpoints
end

Instance Attribute Details

#endpointsObject

Returns the value of attribute endpoints


4
5
6
# File 'lib/minitest/apidoc/group.rb', line 4

def endpoints
  @endpoints
end

#nameObject

Returns the value of attribute name


4
5
6
# File 'lib/minitest/apidoc/group.rb', line 4

def name
  @name
end

Class Method Details

.from(endpoint_hash) ⇒ Object

Takes a hash containing endpoint names as keys and endpoint objects as values

=> #<Minitest::Apidoc::Endpoint>, …)

and turns it into an array containing group objects so that the endpoints whose group attribute is the same are put in the same group.

#<Minitest::Apidoc::Group>, …

Sorts groups by name and endpoints within each group so that GETs are first, then POSTs, PUTs, and so on. The template works with this array to display the documentation.


24
25
26
27
28
29
30
31
# File 'lib/minitest/apidoc/group.rb', line 24

def self.from(endpoint_hash)
  sorted_endpoints = endpoint_hash.values.sort_by do |endpoint|
    Methods::VERBS.index(endpoint.request_method.downcase)
  end
  grouped_endpoints = sorted_endpoints.group_by { |endpoint| endpoint.group }
  groups = grouped_endpoints.map { |group, endpoints| Group.new(group, endpoints) }
  groups.sort_by(&:name)
end