Class: RspecApiDocs::Resource::Example
- Inherits:
-
Object
- Object
- RspecApiDocs::Resource::Example
- Defined in:
- lib/rspec_api_docs/formatter/resource/example.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: DeepHashSet, RequestHeaders
Constant Summary collapse
- MAX_PRECEDENCE =
9_999
Instance Attribute Summary collapse
-
#example ⇒ Object
readonly
Returns the value of attribute example.
Instance Method Summary collapse
-
#description ⇒ String
The description of the example.
-
#http_method ⇒ String?
The HTTP method of first route requested.
-
#initialize(example) ⇒ Example
constructor
A new instance of Example.
- #inspect ⇒ Object
-
#name ⇒ String
The name of the example.
- #notes ⇒ Hash<Symbol,String>?
-
#parameters ⇒ Array<Parameter>
Parameters for the example.
-
#path ⇒ String?
Path stored on the example OR the path of first route requested.
- #precedence ⇒ Integer
-
#requests ⇒ Array<Hash>
Requests stored for the example.
-
#response_fields ⇒ Array<ResponseField>
Response fields for the example.
Constructor Details
#initialize(example) ⇒ Example
Returns a new instance of Example.
11 12 13 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 11 def initialize(example) @example = example end |
Instance Attribute Details
#example ⇒ Object (readonly)
Returns the value of attribute example.
9 10 11 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 9 def example @example end |
Instance Method Details
#description ⇒ String
The description of the example.
E.g. “For getting information about a Character.”
29 30 31 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 29 def description [:description] end |
#http_method ⇒ String?
The HTTP method of first route requested.
85 86 87 88 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 85 def http_method return if request_response_pairs.empty? request_response_pairs.first.first.request_method end |
#inspect ⇒ Object
100 101 102 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 100 def inspect "#<RspecApiDocs::Resource::Example #{name.inspect}, precedence: #{precedence.inspect}>" end |
#name ⇒ String
The name of the example.
E.g. “Returns a Character”
20 21 22 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 20 def name .fetch(:example_name, example.description) end |
#notes ⇒ Hash<Symbol,String>?
91 92 93 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 91 def notes .fetch(:note, {}) end |
#parameters ⇒ Array<Parameter>
Parameters for the example.
36 37 38 39 40 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 36 def parameters .fetch(:parameters, []).map do |name_hash, parameter| Parameter.new(name_hash[:name], parameter) end end |
#path ⇒ String?
Path stored on the example OR the path of first route requested.
75 76 77 78 79 80 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 75 def path .fetch(:path) do return if request_response_pairs.empty? request_response_pairs.first.first.path end end |
#precedence ⇒ Integer
96 97 98 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 96 def precedence .fetch(:example_precedence, MAX_PRECEDENCE) end |
#requests ⇒ Array<Hash>
Requests stored for the example.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 54 def requests # rubocop:disable Metrics/AbcSize request_response_pairs.map do |request, response| { request_method: request.request_method, request_path: request_path(request), request_body: request_body(request.body), request_headers: request_headers(request.env), request_query_parameters: request.params, request_content_type: request.content_type, response_status: response.status, response_status_text: response_status_text(response.status), response_body: response_body(response.body, content_type: response.content_type), response_headers: response_headers(response.headers), response_content_type: response.content_type, } end end |
#response_fields ⇒ Array<ResponseField>
Response fields for the example.
45 46 47 48 49 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 45 def response_fields .fetch(:fields, []).map do |name_hash, field| ResponseField.new(name_hash[:name], field) end end |