Class: Scorpio::OpenAPI::OperationsScope
- Inherits:
-
Object
- Object
- Scorpio::OpenAPI::OperationsScope
- Includes:
- Enumerable
- 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
finds an 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 12 13 14 15 16 17 18 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 9 def initialize(openapi_document) @openapi_document = openapi_document @operations_by_id = Hash.new do |h, operationId| op = detect { |operation| operation.operationId == operationId } unless op raise(::KeyError, "operationId not found: #{operationId.inspect}") end h[operationId] = op end end |
Instance Attribute Details
#openapi_document ⇒ Object (readonly)
Returns the value of attribute openapi_document.
19 20 21 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 19 def openapi_document @openapi_document end |
Instance Method Details
#[](operationId) ⇒ Scorpio::OpenAPI::Operation
finds an operation with the given operationId
37 38 39 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 37 def [](operationId) @operations_by_id[operationId] end |
#each {|Scorpio::OpenAPI::Operation| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/scorpio/openapi/operations_scope.rb', line 22 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 |