Class: Scorpio::OpenAPI::OperationsScope
- Inherits:
-
Object
- Object
- Scorpio::OpenAPI::OperationsScope
- Includes:
- Enumerable, JSI::Util::Memoize
- Defined in:
- lib/scorpio/openapi/operations_scope.rb
Overview
OperationsScope acts as an Enumerable of the Operations for an openapi_document, and offers subscripting by operationId.
Instance Attribute Summary collapse
-
#openapi_document ⇒ Object
readonly
Returns the value of attribute openapi_document.
Instance Method Summary collapse
-
#[](operationId) ⇒ Scorpio::OpenAPI::Operation
The operation with the given operationId.
- #each {|Scorpio::OpenAPI::Operation| ... } ⇒ Object
-
#initialize(openapi_document) ⇒ OperationsScope
constructor
A new instance of OperationsScope.
Constructor Details
#initialize(openapi_document) ⇒ OperationsScope
Returns a new instance of OperationsScope.
9 10 11 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 9 def initialize(openapi_document) @openapi_document = openapi_document end |
Instance Attribute Details
#openapi_document ⇒ Object (readonly)
Returns the value of attribute openapi_document.
12 13 14 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 12 def openapi_document @openapi_document end |
Instance Method Details
#[](operationId) ⇒ Scorpio::OpenAPI::Operation
Returns the operation with the given operationId.
29 30 31 32 33 34 35 36 37 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 29 def [](operationId) jsi_memoize(:[], operationId) do |operationId_| detect { |operation| operation.operationId == operationId_ }.tap do |op| unless op raise(::KeyError, "operationId not found: #{operationId_.inspect}") end end end end |
#each {|Scorpio::OpenAPI::Operation| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 15 def each openapi_document.paths.each do |path, path_item| path_item.each do |http_method, operation| if operation.is_a?(Scorpio::OpenAPI::Operation) yield operation end end end end |