Class: Scorpio::OpenAPI::OperationsScope

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/scorpio/openapi/operations_scope.rb

Overview

OperationsScope is an Enumerable for a collection of Operations, and offers subscripting by operationId.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ OperationsScope

Returns a new instance of OperationsScope.

Parameters:

  • enum (Enumerable)


9
10
11
12
13
14
# File 'lib/scorpio/openapi/operations_scope.rb', line 9

def initialize(enum)
  @enum = enum
  @operations_by_id = Hash.new do |h, operationId|
    h[operationId] = enum.detect { |operation| operation.operationId == operationId }
  end
end

Instance Attribute Details

#openapi_documentObject (readonly)

Returns the value of attribute openapi_document.



15
16
17
# File 'lib/scorpio/openapi/operations_scope.rb', line 15

def openapi_document
  @openapi_document
end

Instance Method Details

#by_id(operationId) ⇒ Scorpio::OpenAPI::Operation?

Returns:



25
26
27
# File 'lib/scorpio/openapi/operations_scope.rb', line 25

def by_id(operationId)
  @operations_by_id[operationId]
end

#by_id!(operationId) ⇒ Scorpio::OpenAPI::Operation Also known as: []

finds an operation with the given operationId

Parameters:

  • operationId (String)

    the operationId of the operation to find

Returns:

Raises:

  • (::KeyError)

    if the given operationId does not exist



33
34
35
# File 'lib/scorpio/openapi/operations_scope.rb', line 33

def by_id!(operationId)
  @operations_by_id[operationId] || raise(::KeyError, -"operationId not found: #{operationId.inspect}")
end

#each {|Scorpio::OpenAPI::Operation| ... } ⇒ Object



18
19
20
# File 'lib/scorpio/openapi/operations_scope.rb', line 18

def each(&block)
  @enum.each(&block)
end

#reject(&block) ⇒ OperationsScope

Returns:



45
46
47
# File 'lib/scorpio/openapi/operations_scope.rb', line 45

def reject(&block)
  OperationsScope.new(@enum.reject(&block))
end

#select(&block) ⇒ OperationsScope

Returns:



40
41
42
# File 'lib/scorpio/openapi/operations_scope.rb', line 40

def select(&block)
  OperationsScope.new(@enum.select(&block))
end

#tagged(tag) ⇒ OperationsScope

Operations with the indicated tag

Parameters:

Returns:



52
53
54
55
# File 'lib/scorpio/openapi/operations_scope.rb', line 52

def tagged(tag)
  tag_name = tag.is_a?(OpenAPI::Tag) ? tag.name : tag
  select { |op| op.tagged?(tag_name) }
end