Class: Turbo::Train::TestServer

Inherits:
BaseServer show all
Defined in:
lib/turbo/train/test_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseServer

#listen_url, #publish_url, #server_config

Constructor Details

#initialize(real_server, configuration) ⇒ TestServer

Returns a new instance of TestServer.



6
7
8
9
10
# File 'lib/turbo/train/test_server.rb', line 6

def initialize(real_server, configuration)
  @configuration = configuration
  @channels_data = {}
  @real_server = real_server
end

Instance Attribute Details

#channels_dataObject (readonly)

Returns the value of attribute channels_data.



4
5
6
# File 'lib/turbo/train/test_server.rb', line 4

def channels_data
  @channels_data
end

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/turbo/train/test_server.rb', line 4

def configuration
  @configuration
end

#real_serverObject (readonly)

Returns the value of attribute real_server.



4
5
6
# File 'lib/turbo/train/test_server.rb', line 4

def real_server
  @real_server
end

Instance Method Details

#broadcasts(channel) ⇒ Object



21
22
23
# File 'lib/turbo/train/test_server.rb', line 21

def broadcasts(channel)
  channels_data[channel] ||= []
end

#clearObject



29
30
31
# File 'lib/turbo/train/test_server.rb', line 29

def clear
  @channels_data = []
end

#clear_messages(channel) ⇒ Object



25
26
27
# File 'lib/turbo/train/test_server.rb', line 25

def clear_messages(channel)
  channels_data[channel] = []
end

#publish(topics:, data:) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/turbo/train/test_server.rb', line 12

def publish(topics:, data:)
  Array(topics).each do |topic|
    @channels_data[topic] ||= []
    @channels_data[topic] << data[:data]
  end

  real_server.publish(topics: topics, data: data) if real_server
end