Class: CrapServer::ConnectionInstance
- Inherits:
-
Object
- Object
- CrapServer::ConnectionInstance
- Defined in:
- lib/crap_server/connection_instance.rb
Overview
This is the class used to bind the block that is passed to run!. Every method defined here is available inside the run! block
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#config ⇒ Object
Returns the value of attribute config.
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
- #close ⇒ Object
- #close_after_write ⇒ Object
-
#initialize ⇒ ConnectionInstance
constructor
A new instance of ConnectionInstance.
-
#logger ⇒ Object
Give access to logger class to the user.
-
#run(data, &block) ⇒ Object
This method execute the block sent to run! method.
-
#write(string) ⇒ Object
Write to the client the given string.
Constructor Details
#initialize ⇒ ConnectionInstance
Returns a new instance of ConnectionInstance.
9 |
# File 'lib/crap_server/connection_instance.rb', line 9 def initialize; end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
6 7 8 |
# File 'lib/crap_server/connection_instance.rb', line 6 def address @address end |
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/crap_server/connection_instance.rb', line 7 def config @config end |
#handler ⇒ Object
Returns the value of attribute handler.
8 9 10 |
# File 'lib/crap_server/connection_instance.rb', line 8 def handler @handler end |
#socket ⇒ Object
Returns the value of attribute socket.
5 6 7 |
# File 'lib/crap_server/connection_instance.rb', line 5 def socket @socket end |
Instance Method Details
#close ⇒ Object
30 31 32 |
# File 'lib/crap_server/connection_instance.rb', line 30 def close @handler.close @socket end |
#close_after_write ⇒ Object
26 27 28 |
# File 'lib/crap_server/connection_instance.rb', line 26 def close_after_write @handler.set_close_after_write @socket end |
#logger ⇒ Object
Give access to logger class to the user
35 36 37 |
# File 'lib/crap_server/connection_instance.rb', line 35 def logger CrapServer::Application.send(:logger) end |
#run(data, &block) ⇒ Object
This method execute the block sent to run! method
12 13 14 15 16 17 18 |
# File 'lib/crap_server/connection_instance.rb', line 12 def run(data, &block) # Undefine the last definition if was defined undef :call if self.respond_to? :call # Define the new method to bind the block with this class. self.class.send :define_method, :call, &block self.call(data) end |
#write(string) ⇒ Object
Write to the client the given string
21 22 23 24 |
# File 'lib/crap_server/connection_instance.rb', line 21 def write(string) @handler.add_to_write @socket @handler.set_buffer @socket, string end |