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
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, #disconnect_expected, #nickname, #nicks, #original_opts, #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=, #default_channels, #default_channels=, #handle_client_connected, #handle_incoming_numeric, #handle_incoming_ping, #handle_nick_taken, #handle_welcome, #join, #msg, #nick, #part, #pong, #process_connect, #process_disconnect, #quit, #receive_line, setup
Methods included from Dispatchable
Constructor Details
#initialize(opts = {}) ⇒ TestClient
Returns a new instance of TestClient.
15 16 17 18 19 20 21 22 |
# File 'lib/marvin/test_client.rb', line 15 def initialize(opts = {}) super self.incoming_commands = [] self.outgoing_commands = [] self.dispatched_events = [] self.connection_open = false self.instances << self end |
Instance Attribute Details
#connection_open ⇒ Object
Returns the value of attribute connection_open.
8 9 10 |
# File 'lib/marvin/test_client.rb', line 8 def connection_open @connection_open end |
#dispatched_events ⇒ Object
Returns the value of attribute dispatched_events.
8 9 10 |
# File 'lib/marvin/test_client.rb', line 8 def dispatched_events @dispatched_events end |
#incoming_commands ⇒ Object
Returns the value of attribute incoming_commands.
8 9 10 |
# File 'lib/marvin/test_client.rb', line 8 def incoming_commands @incoming_commands end |
#last_sent ⇒ Object
Returns the value of attribute last_sent.
8 9 10 |
# File 'lib/marvin/test_client.rb', line 8 def last_sent @last_sent end |
#outgoing_commands ⇒ Object
Returns the value of attribute outgoing_commands.
8 9 10 |
# File 'lib/marvin/test_client.rb', line 8 def outgoing_commands @outgoing_commands end |
Class Method Details
.add_reconnect(opts = {}) ⇒ Object
59 60 61 |
# File 'lib/marvin/test_client.rb', line 59 def self.add_reconnect(opts = {}) Marvin::Logger.info "Added reconnect with options: #{opts.inspect}" end |
.run ⇒ Object
47 48 49 50 51 |
# File 'lib/marvin/test_client.rb', line 47 def self.run self.instances.each do |i| i.connection_open = true end end |
.stop ⇒ Object
53 54 55 56 57 |
# File 'lib/marvin/test_client.rb', line 53 def self.stop self.instances.each do |i| i.connection_open = false end end |
Instance Method Details
#connection_open? ⇒ Boolean
24 25 26 |
# File 'lib/marvin/test_client.rb', line 24 def connection_open? self.connection_open end |
#dispatch(name, opts = {}) ⇒ Object
42 43 44 45 |
# File 'lib/marvin/test_client.rb', line 42 def dispatch(name, opts = {}) self.dispatched_events << [name, opts] super(name, opts) end |
#send_line(*args) ⇒ Object
28 29 30 31 |
# File 'lib/marvin/test_client.rb', line 28 def send_line(*args) self.outgoing_commands += args self.last_sent = args.last end |
#test_command(name, *args) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/marvin/test_client.rb', line 33 def test_command(name, *args) = args. host_mask = .delete(:host_mask) || ":[email protected]" name = name.to_s.upcase args = args.flatten.compact irc_command = "#{host_mask} #{name} #{args.join(" ").strip}" self.receive_line irc_command end |