Class: Apipie::Generator::Swagger::ResourceDescriptionsCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/resource_description_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource_descriptions) ⇒ ResourceDescriptionsCollection

Returns a new instance of ResourceDescriptionsCollection.

Parameters:



3
4
5
# File 'lib/apipie/generator/swagger/resource_description_collection.rb', line 3

def initialize(resource_descriptions)
  @resource_descriptions = resource_descriptions
end

Instance Method Details

#filter(version:, resource_id:, method_name: nil) ⇒ Array<Apipie::ResourceDescription>

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apipie/generator/swagger/resource_description_collection.rb', line 8

def filter(version:, resource_id:, method_name: nil)
  resources = []

  # If resource_id is blank, take just resources which have some methods because
  # we dont want to show eg ApplicationController as resource
  # otherwise, take only the specified resource
  @resource_descriptions[version].each do |resource_description_id, resource_description|
    if (resource_id.blank? && resource_description._methods.present?) || resource_description_id == resource_id
      resources << resource_description
    end
  end

  if method_name.present?
    resources = resources.select do |resource_description|
      resource_description._methods.select do |method_description_name, _|
        method_description_name == method_name
      end.present?
    end
  end

  resources
end