Class: RubstApi::Route
- Inherits:
-
Object
- Object
- RubstApi::Route
- Defined in:
- lib/rubst_api/routing.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#deprecated ⇒ Object
readonly
Returns the value of attribute deprecated.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#include_in_schema ⇒ Object
readonly
Returns the value of attribute include_in_schema.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operation_id ⇒ Object
readonly
Returns the value of attribute operation_id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#response_model ⇒ Object
readonly
Returns the value of attribute response_model.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #allowed?(method) ⇒ Boolean
-
#initialize(path, endpoint:, methods:, params: {}, response_model: nil, status_code: 200, tags: [], summary: nil, description: nil, operation_id: nil, deprecated: false, include_in_schema: true, responses: {}, dependencies: [], name: nil) ⇒ Route
constructor
A new instance of Route.
- #match(request_path) ⇒ Object
- #unique_id ⇒ Object
Constructor Details
#initialize(path, endpoint:, methods:, params: {}, response_model: nil, status_code: 200, tags: [], summary: nil, description: nil, operation_id: nil, deprecated: false, include_in_schema: true, responses: {}, dependencies: [], name: nil) ⇒ Route
Returns a new instance of Route.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rubst_api/routing.rb', line 9 def initialize(path, endpoint:, methods:, params: {}, response_model: nil, status_code: 200, tags: [], summary: nil, description: nil, operation_id: nil, deprecated: false, include_in_schema: true, responses: {}, dependencies: [], name: nil, **) @path, @endpoint, @methods, @params = normalize_path(path), endpoint, Array(methods).map { |m| m.to_s.upcase }, params @response_model, @status_code, @tags = response_model, status_code, @summary, @description, @operation_id = summary, description, operation_id @deprecated, @include_in_schema, @responses = deprecated, include_in_schema, responses @dependencies, @name = dependencies, name @regexp, @path_names = compile(@path) end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def dependencies @dependencies end |
#deprecated ⇒ Object (readonly)
Returns the value of attribute deprecated.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def deprecated @deprecated end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def description @description end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def endpoint @endpoint end |
#include_in_schema ⇒ Object (readonly)
Returns the value of attribute include_in_schema.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def include_in_schema @include_in_schema end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def methods @methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def name @name end |
#operation_id ⇒ Object (readonly)
Returns the value of attribute operation_id.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def operation_id @operation_id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def path @path end |
#response_model ⇒ Object (readonly)
Returns the value of attribute response_model.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def response_model @response_model end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def responses @responses end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def status_code @status_code end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def summary @summary end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'lib/rubst_api/routing.rb', line 5 def @tags end |
Instance Method Details
#allowed?(method) ⇒ Boolean
25 |
# File 'lib/rubst_api/routing.rb', line 25 def allowed?(method) = methods.include?(method) || (method == "HEAD" && methods.include?("GET")) |
#match(request_path) ⇒ Object
20 21 22 23 |
# File 'lib/rubst_api/routing.rb', line 20 def match(request_path) match = @regexp.match(request_path) match&.named_captures || nil end |
#unique_id ⇒ Object
27 28 29 |
# File 'lib/rubst_api/routing.rb', line 27 def unique_id operation_id || "#{name || endpoint_name}_#{path.gsub(/\W+/, "_")}_#{methods.first.downcase}".gsub(/\A_|_\z/, "") end |