Class: Marvin::TestClient
- Inherits:
-
AbstractClient
- Object
- AbstractClient
- Marvin::TestClient
- Defined in:
- lib/marvin/test_client.rb
Overview
Marvin::TestClient is a simple client used for testing Marvin::Base derivatives in a non-network-reliant setting.
Defined Under Namespace
Classes: DispatchedEvents
Constant Summary collapse
- @@instances =
[]
Instance Attribute Summary collapse
-
#connection_open ⇒ Object
Returns the value of attribute connection_open.
-
#dispatched_events ⇒ Object
Returns the value of attribute dispatched_events.
-
#incoming_commands ⇒ Object
Returns the value of attribute incoming_commands.
-
#last_sent ⇒ Object
Returns the value of attribute last_sent.
-
#outgoing_commands ⇒ Object
Returns the value of attribute outgoing_commands.
Attributes inherited from AbstractClient
#channels, #connection_config, #disconnect_expected, #nickname, #nicks, #pass, #port, #server
Class Method Summary collapse
Instance Method Summary collapse
- #connection_open? ⇒ Boolean
- #dispatch(name, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ TestClient
constructor
A new instance of TestClient.
- #send_line(*args) ⇒ Object
- #test_command(name, *args) ⇒ Object
Methods inherited from AbstractClient
#action, #command, configuration=, configure, #default_channels, #default_channels=, #handle_client_connected, #handle_incoming_error, #handle_incoming_join, #handle_incoming_numeric, #handle_incoming_ping, #handle_nick_taken, #handle_welcome, #host_with_port, #join, #msg, #nick, #part, #pong, #process_connect, #process_development, #process_disconnect, #quit, #receive_line, setup, setup?, #setup_handlers
Constructor Details
#initialize(opts = {}) ⇒ TestClient
Returns a new instance of TestClient.
14 15 16 17 18 19 20 21 |
# File 'lib/marvin/test_client.rb', line 14 def initialize(opts = {}) super @incoming_commands = [] @outgoing_commands = [] @dispatched_events = [] @connection_open = false @@instances << self end |
Instance Attribute Details
#connection_open ⇒ Object
Returns the value of attribute connection_open.
6 7 8 |
# File 'lib/marvin/test_client.rb', line 6 def connection_open @connection_open end |
#dispatched_events ⇒ Object
Returns the value of attribute dispatched_events.
6 7 8 |
# File 'lib/marvin/test_client.rb', line 6 def dispatched_events @dispatched_events end |
#incoming_commands ⇒ Object
Returns the value of attribute incoming_commands.
6 7 8 |
# File 'lib/marvin/test_client.rb', line 6 def incoming_commands @incoming_commands end |
#last_sent ⇒ Object
Returns the value of attribute last_sent.
6 7 8 |
# File 'lib/marvin/test_client.rb', line 6 def last_sent @last_sent end |
#outgoing_commands ⇒ Object
Returns the value of attribute outgoing_commands.
6 7 8 |
# File 'lib/marvin/test_client.rb', line 6 def outgoing_commands @outgoing_commands end |
Class Method Details
.add_reconnect(opts = {}) ⇒ Object
53 54 55 |
# File 'lib/marvin/test_client.rb', line 53 def self.add_reconnect(opts = {}) logger.info "Added reconnect with options: #{opts.inspect}" end |
.run ⇒ Object
45 46 47 |
# File 'lib/marvin/test_client.rb', line 45 def self.run @@instances.each { |i| i.connection_open = true } end |
.stop ⇒ Object
49 50 51 |
# File 'lib/marvin/test_client.rb', line 49 def self.stop @@instances.each { |i| i.connection_open = false } end |
Instance Method Details
#connection_open? ⇒ Boolean
23 24 25 |
# File 'lib/marvin/test_client.rb', line 23 def connection_open? !!@connection_open end |
#dispatch(name, opts = {}) ⇒ Object
40 41 42 43 |
# File 'lib/marvin/test_client.rb', line 40 def dispatch(name, opts = {}) @dispatched_events << [name, opts] super(name, opts) end |
#send_line(*args) ⇒ Object
27 28 29 30 |
# File 'lib/marvin/test_client.rb', line 27 def send_line(*args) @outgoing_commands += args @last_sent = args.last end |
#test_command(name, *args) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/marvin/test_client.rb', line 32 def test_command(name, *args) = args. host_mask = .delete(:host_mask) || ":[email protected]" name = name.to_s.upcase args = args.flatten.compact receive_line "#{host_mask} #{name} #{args.join(" ").strip}" end |