Class: Marvin::IRC::Client::EMConnection
- Inherits:
-
EventMachine::Protocols::LineAndTextProtocol
- Object
- EventMachine::Protocols::LineAndTextProtocol
- Marvin::IRC::Client::EMConnection
- Defined in:
- lib/marvin/irc/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #connected! ⇒ Object
- #host_with_port ⇒ Object
-
#initialize(*args) ⇒ EMConnection
constructor
A new instance of EMConnection.
- #post_init ⇒ Object
- #receive_line(line) ⇒ Object
- #send_line(*lines) ⇒ Object
- #should_use_ssl? ⇒ Boolean
- #ssl_handshake_completed ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(*args) ⇒ EMConnection
Returns a new instance of EMConnection.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/marvin/irc/client.rb', line 15 def initialize(*args) @configuration = args.last.is_a?(Marvin::Nash) ? args.pop : Marvin::Nash.new super(*args) @client = Marvin::IRC::Client.new(@configuration) @client.em_connection = self @connected = false rescue Exception => e Marvin::ExceptionTracker.log(e) Marvin::IRC::Client.stop end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/marvin/irc/client.rb', line 13 def client @client end |
#configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/marvin/irc/client.rb', line 13 def configuration @configuration end |
#port ⇒ Object
Returns the value of attribute port.
13 14 15 |
# File 'lib/marvin/irc/client.rb', line 13 def port @port end |
Instance Method Details
#connected! ⇒ Object
70 71 72 73 |
# File 'lib/marvin/irc/client.rb', line 70 def connected! @connected = true @client.process_connect end |
#host_with_port ⇒ Object
79 80 81 |
# File 'lib/marvin/irc/client.rb', line 79 def host_with_port "#{@configuration.host}:#{@configuration.port}" end |
#post_init ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/marvin/irc/client.rb', line 26 def post_init super if should_use_ssl? logger.info "Starting SSL for #{host_with_port}" start_tls else connected! end rescue Exception => e Marvin::ExceptionTracker.log(e) Marvin::IRC::Client.stop end |
#receive_line(line) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/marvin/irc/client.rb', line 52 def receive_line(line) return unless @connected line = line.strip logger.debug "<< #{line}" @client.receive_line(line) rescue Exception => e logger.warn "Uncaught exception raised; Likely in Marvin" Marvin::ExceptionTracker.log(e) end |
#send_line(*lines) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/marvin/irc/client.rb', line 62 def send_line(*lines) return unless @connected lines.each do |line| logger.debug ">> #{line.strip}" send_data line end end |
#should_use_ssl? ⇒ Boolean
75 76 77 |
# File 'lib/marvin/irc/client.rb', line 75 def should_use_ssl? @should_use_ssl ||= @configuration.ssl? end |
#ssl_handshake_completed ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/marvin/irc/client.rb', line 39 def ssl_handshake_completed logger.info "SSL handshake completed for #{host_with_port}" connected! if should_use_ssl? rescue Exception => e Marvin::ExceptionTracker.log(e) Marvin::IRC::Client.stop end |
#unbind ⇒ Object
47 48 49 50 |
# File 'lib/marvin/irc/client.rb', line 47 def unbind @client.process_disconnect super end |