Class: Fix::Engine::Client
- Inherits:
-
Object
- Object
- Fix::Engine::Client
- Includes:
- Logger
- Defined in:
- lib/fix/engine/client.rb
Overview
Represents a connected client
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.count ⇒ Fixnum
Returns the count of currently connected clients.
-
.delete(ip, port) ⇒ Object
Removes a client from the currently connected ones.
-
.get(ip, port, connection = nil) ⇒ Fix::Engine::Client
Returns a client instance from its connection IP.
-
.key(ip, port) ⇒ String
Returns an identifier for the given IP and port.
Instance Method Summary collapse
-
#delete ⇒ Object
Removes the current client from the array of connected ones.
-
#initialize(ip, port, connection) ⇒ Client
constructor
A new instance of Client.
-
#key ⇒ String
Returns an identifier for the current client.
Methods included from Logger
Constructor Details
#initialize(ip, port, connection) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 |
# File 'lib/fix/engine/client.rb', line 17 def initialize(ip, port, connection) @ip = ip @port = port @connection = connection self.class.instance_variable_get(:@clients)[key] = self end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
13 14 15 |
# File 'lib/fix/engine/client.rb', line 13 def connection @connection end |
#ip ⇒ Object
Returns the value of attribute ip.
13 14 15 |
# File 'lib/fix/engine/client.rb', line 13 def ip @ip end |
#port ⇒ Object
Returns the value of attribute port.
13 14 15 |
# File 'lib/fix/engine/client.rb', line 13 def port @port end |
#username ⇒ Object
Returns the value of attribute username.
13 14 15 |
# File 'lib/fix/engine/client.rb', line 13 def username @username end |
Class Method Details
.count ⇒ Fixnum
Returns the count of currently connected clients
42 43 44 |
# File 'lib/fix/engine/client.rb', line 42 def self.count @clients.count end |
.delete(ip, port) ⇒ Object
Removes a client from the currently connected ones
52 53 54 |
# File 'lib/fix/engine/client.rb', line 52 def self.delete(ip, port) @clients.delete(key(ip, port)) end |
.get(ip, port, connection = nil) ⇒ Fix::Engine::Client
Returns a client instance from its connection IP
33 34 35 |
# File 'lib/fix/engine/client.rb', line 33 def self.get(ip, port, connection = nil) @clients[key(ip, port)] || Client.new(ip, port, connection) end |
.key(ip, port) ⇒ String
Returns an identifier for the given IP and port
80 81 82 |
# File 'lib/fix/engine/client.rb', line 80 def self.key(ip, port) "#{ip}:#{port}" end |
Instance Method Details
#delete ⇒ Object
Removes the current client from the array of connected ones
68 69 70 |
# File 'lib/fix/engine/client.rb', line 68 def delete self.class.delete(ip, port) end |
#key ⇒ String
Returns an identifier for the current client
61 62 63 |
# File 'lib/fix/engine/client.rb', line 61 def key self.class.key(ip, port) end |