Class: Apipie::Generator::Swagger::ResourceDescriptionsCollection
- Inherits:
-
Object
- Object
- Apipie::Generator::Swagger::ResourceDescriptionsCollection
- Defined in:
- lib/apipie/generator/swagger/resource_description_collection.rb
Instance Method Summary collapse
- #filter(version:, resource_id:, method_name: nil) ⇒ Array<Apipie::ResourceDescription>
-
#initialize(resource_descriptions) ⇒ ResourceDescriptionsCollection
constructor
A new instance of ResourceDescriptionsCollection.
Constructor Details
#initialize(resource_descriptions) ⇒ ResourceDescriptionsCollection
Returns a new instance of ResourceDescriptionsCollection.
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>
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.any? do |method_description_name, _| method_description_name == method_name end end end resources end |