Class: CrapServer::ConnectionInstance

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConnectionInstance

Returns a new instance of ConnectionInstance.



9
# File 'lib/crap_server/connection_instance.rb', line 9

def initialize; end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



6
7
8
# File 'lib/crap_server/connection_instance.rb', line 6

def address
  @address
end

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/crap_server/connection_instance.rb', line 7

def config
  @config
end

#handlerObject

Returns the value of attribute handler.



8
9
10
# File 'lib/crap_server/connection_instance.rb', line 8

def handler
  @handler
end

#socketObject

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

#closeObject



30
31
32
# File 'lib/crap_server/connection_instance.rb', line 30

def close
  @handler.close @socket
end

#close_after_writeObject



26
27
28
# File 'lib/crap_server/connection_instance.rb', line 26

def close_after_write
  @handler.set_close_after_write @socket
end

#loggerObject

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