Class: Turbo::Train::TestServer
- Inherits:
-
BaseServer
- Object
- BaseServer
- Turbo::Train::TestServer
- Defined in:
- lib/turbo/train/test_server.rb
Instance Attribute Summary collapse
-
#channels_data ⇒ Object
readonly
Returns the value of attribute channels_data.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#real_server ⇒ Object
readonly
Returns the value of attribute real_server.
Instance Method Summary collapse
- #broadcasts(channel) ⇒ Object
- #clear ⇒ Object
- #clear_messages(channel) ⇒ Object
-
#initialize(real_server, configuration) ⇒ TestServer
constructor
A new instance of TestServer.
- #publish(topics:, data:) ⇒ Object
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_data ⇒ Object (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 |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/turbo/train/test_server.rb', line 4 def configuration @configuration end |
#real_server ⇒ Object (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 |
#clear ⇒ Object
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 (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 |