Class: Scorpio::OpenAPI::OperationsScope

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(openapi_document) ⇒ OperationsScope

Returns a new instance of OperationsScope.

Parameters:



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_documentObject (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.

Parameters:

  • operationId

Returns:

Raises:

  • (::KeyError)

    if the given operationId does not exist



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