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/request_headers.rb
Defined Under Namespace
Classes: RequestHeaders
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.
-
#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.
-
#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.
8 9 10 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 8 def initialize(example) @example = example end |
Instance Attribute Details
#example ⇒ Object (readonly)
Returns the value of attribute example.
6 7 8 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 6 def example @example end |
Instance Method Details
#description ⇒ String
The description of the example.
E.g. “For getting information about a Character.”
26 27 28 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 26 def description [:description] end |
#http_method ⇒ String?
The HTTP method of first route requested.
82 83 84 85 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 82 def http_method return if request_response_pairs.empty? request_response_pairs.first.first.request_method end |
#name ⇒ String
The name of the example.
E.g. “Returns a Character”
17 18 19 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 17 def name .fetch(:example_name, example.description) end |
#notes ⇒ Hash<Symbol,String>?
88 89 90 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 88 def notes .fetch(:note, {}) end |
#parameters ⇒ Array<Parameter>
Parameters for the example.
33 34 35 36 37 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 33 def parameters .fetch(:parameters, []).map do |name, parameter| Parameter.new(name, parameter) end end |
#path ⇒ String?
Path stored on the example OR the path of first route requested.
72 73 74 75 76 77 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 72 def path .fetch(:path) do return if request_response_pairs.empty? request_response_pairs.first.first.path end end |
#requests ⇒ Array<Hash>
Requests stored for the example.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 51 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), response_headers: response.headers, response_content_type: response.content_type, } end end |
#response_fields ⇒ Array<ResponseField>
Response fields for the example.
42 43 44 45 46 |
# File 'lib/rspec_api_docs/formatter/resource/example.rb', line 42 def response_fields .fetch(:fields, []).map do |name, field| ResponseField.new(name, field) end end |