Class: RspecApiDocs::ResourceCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_docs/resource_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(resources = {}) ⇒ ResourceCollection


3
4
5
# File 'lib/rspec_api_docs/resource_collection.rb', line 3

def initialize(resources = {})
  @resources = resources
end

Instance Method Details

#add_example(rspec_example) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rspec_api_docs/resource_collection.rb', line 11

def add_example(rspec_example)
  resource = Resource.new(rspec_example)

  existing_resource = @resources[resource.name]
  if existing_resource
    existing_resource.precedence = [existing_resource.precedence, resource.precedence].min
    resource = existing_resource
  else
    @resources[resource.name] = resource
  end

  resource.add_example Resource::Example.new(rspec_example)
end

#allObject


7
8
9
# File 'lib/rspec_api_docs/resource_collection.rb', line 7

def all
  @resources.values.sort_by { |resource| [resource.precedence, resource.name] }
end