Class: RspecApiDocs::Resource
- Inherits:
-
Object
- Object
- RspecApiDocs::Resource
- Defined in:
- lib/rspec_api_docs/formatter/resource.rb,
lib/rspec_api_docs/formatter/resource/example.rb,
lib/rspec_api_docs/formatter/resource/parameter.rb,
lib/rspec_api_docs/formatter/resource/response_field.rb,
lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb,
lib/rspec_api_docs/formatter/resource/example/request_headers.rb
Defined Under Namespace
Classes: Example, Parameter, ResponseField
Constant Summary collapse
- MAX_PRECEDENCE =
9_999
Instance Attribute Summary collapse
-
#rspec_example ⇒ Object
readonly
Returns the value of attribute rspec_example.
Instance Method Summary collapse
-
#add_example(example) ⇒ void
Add an example.
-
#description ⇒ String
The description of the resource.
-
#examples ⇒ Array<Example>
Returns an array of Examples.
-
#initialize(rspec_example) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
-
#name ⇒ String
The name of the resource.
- #precedence ⇒ Integer
-
#precedence=(value) ⇒ void
Set the resource precedence.
Constructor Details
#initialize(rspec_example) ⇒ Resource
Returns a new instance of Resource.
11 12 13 14 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 11 def initialize(rspec_example) @rspec_example = rspec_example @examples = [] end |
Instance Attribute Details
#rspec_example ⇒ Object (readonly)
Returns the value of attribute rspec_example.
9 10 11 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 9 def rspec_example @rspec_example end |
Instance Method Details
#add_example(example) ⇒ void
This method returns an undefined value.
Add an example
44 45 46 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 44 def add_example(example) @examples << example end |
#description ⇒ String
The description of the resource.
E.g. “Orders can be created, viewed, and deleted”
30 31 32 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 30 def description [:resource_description] end |
#examples ⇒ Array<Example>
Returns an array of Examples
37 38 39 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 37 def examples @examples.sort_by { |example| [example.precedence, example.name] } end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 60 def inspect "#<RspecApiDocs::Resource #{name.inspect}, @examples=#{examples.inspect}>" end |
#name ⇒ String
The name of the resource.
E.g. “Characters”
21 22 23 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 21 def name .fetch(:resource_name) { rspec_example.[:example_group][:description] } end |
#precedence ⇒ Integer
49 50 51 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 49 def precedence @precedence ||= .fetch(:resource_precedence, MAX_PRECEDENCE) end |
#precedence=(value) ⇒ void
This method returns an undefined value.
Set the resource precedence
56 57 58 |
# File 'lib/rspec_api_docs/formatter/resource.rb', line 56 def precedence=(value) @precedence = value end |