Class: AsyncapiCable::Dsl::OperationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/asyncapi_cable/dsl/operation_context.rb

Constant Summary collapse

KINDS =
%i[subscribe broadcast publish].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, summary = nil) ⇒ OperationContext

Returns a new instance of OperationContext.



9
10
11
12
13
14
15
16
17
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 9

def initialize(kind, summary = nil)
  unless KINDS.include?(kind)
    raise ArgumentError, "operation kind must be one of #{KINDS.inspect}, got #{kind.inspect}"
  end
  @kind = kind
  @summary = summary
  @messages = []
  @operation_id = nil
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 6

def kind
  @kind
end

#messagesObject (readonly)

Returns the value of attribute messages.



6
7
8
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 6

def messages
  @messages
end

#operation_idObject

Returns the value of attribute operation_id.



7
8
9
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 7

def operation_id
  @operation_id
end

#summaryObject (readonly)

Returns the value of attribute summary.



6
7
8
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 6

def summary
  @summary
end

Instance Method Details

#message(component_class) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 19

def message(component_class)
  unless component_class.is_a?(Class) && component_class < OpenapiRuby::Components::Base
    raise ArgumentError, "message must be an OpenapiRuby::Components::Base subclass, got #{component_class.inspect}"
  end
  @messages << component_class
  component_class
end

#operationId(value) ⇒ Object



27
28
29
# File 'lib/asyncapi_cable/dsl/operation_context.rb', line 27

def operationId(value)
  @operation_id = value
end