Class: OpenapiContracts::OperationRouter
- Inherits:
-
Object
- Object
- OpenapiContracts::OperationRouter
- Defined in:
- lib/openapi_contracts/operation_router.rb
Instance Method Summary collapse
-
#initialize(doc) ⇒ OperationRouter
constructor
A new instance of OperationRouter.
- #route(actual_path, method) ⇒ Object
Constructor Details
#initialize(doc) ⇒ OperationRouter
Returns a new instance of OperationRouter.
3 4 5 6 |
# File 'lib/openapi_contracts/operation_router.rb', line 3 def initialize(doc) @doc = doc @dynamic_paths = doc.paths.select(&:dynamic?) end |
Instance Method Details
#route(actual_path, method) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/openapi_contracts/operation_router.rb', line 8 def route(actual_path, method) @doc.with_path(actual_path)&.then { |p| return p.with_method(method) } @dynamic_paths.each do |path| next unless path.supports_method?(method) next unless m = path.path_regexp.match(actual_path) operation = path.with_method(method) parameters = (path.parameters + operation.parameters).select(&:in_path?) return operation if parameter_match?(m.named_captures, parameters) end nil end |