Class: MockServer::HttpWebSocketResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subprotocol: nil, messages: nil, matchers: nil, close_connection: nil, delay: nil, primary: nil) ⇒ HttpWebSocketResponse

Returns a new instance of HttpWebSocketResponse.



1486
1487
1488
1489
1490
1491
1492
1493
# File 'lib/mockserver/models.rb', line 1486

def initialize(subprotocol: nil, messages: nil, matchers: nil, close_connection: nil, delay: nil, primary: nil)
  @subprotocol = subprotocol
  @messages = messages
  @matchers = matchers
  @close_connection = close_connection
  @delay = delay
  @primary = primary
end

Instance Attribute Details

#close_connectionObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def close_connection
  @close_connection
end

#delayObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def delay
  @delay
end

#matchersObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def matchers
  @matchers
end

#messagesObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def messages
  @messages
end

#primaryObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def primary
  @primary
end

#subprotocolObject

matchers carries per-incoming-frame response rules (server HttpWebSocketResponseDTO.matchers); each is a WebSocketFrameMatcher.



1484
1485
1486
# File 'lib/mockserver/models.rb', line 1484

def subprotocol
  @subprotocol
end

Class Method Details

.from_hash(data) ⇒ Object



1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
# File 'lib/mockserver/models.rb', line 1506

def self.from_hash(data)
  return nil if data.nil?

  messages_data = data['messages']
  messages = messages_data&.map { |m| WebSocketMessage.from_hash(m) }
  matchers_data = data['matchers']
  matchers = matchers_data&.map { |m| WebSocketFrameMatcher.from_hash(m) }
  new(
    subprotocol:      data['subprotocol'],
    messages:         messages,
    matchers:         matchers,
    close_connection: data['closeConnection'],
    delay:            Delay.from_hash(data['delay']),
    primary:          data['primary']
  )
end

Instance Method Details

#to_hObject



1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
# File 'lib/mockserver/models.rb', line 1495

def to_h
  result = {}
  result['subprotocol'] = @subprotocol unless @subprotocol.nil?
  result['messages'] = @messages&.map(&:to_h) if @messages
  result['matchers'] = @matchers&.map(&:to_h) if @matchers
  result['closeConnection'] = @close_connection unless @close_connection.nil?
  result['delay'] = @delay.to_h if @delay
  result['primary'] = @primary unless @primary.nil?
  result
end