Class: Specjour::Printer
- Inherits:
-
Object
- Object
- Specjour::Printer
- Includes:
- Protocol
- Defined in:
- lib/specjour/printer.rb
Constant Summary collapse
- RANDOM_PORT =
0
Constants included from Protocol
Specjour::Protocol::TERMINATOR, Specjour::Protocol::TERMINATOR_REGEXP
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#example_size ⇒ Object
Returns the value of attribute example_size.
-
#examples_complete ⇒ Object
Returns the value of attribute examples_complete.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#profiler ⇒ Object
Returns the value of attribute profiler.
-
#tests_to_run ⇒ Object
Returns the value of attribute tests_to_run.
Instance Method Summary collapse
- #exit_status ⇒ Object
-
#initialize ⇒ Printer
constructor
A new instance of Printer.
- #start ⇒ Object
Methods included from Protocol
Constructor Details
#initialize ⇒ Printer
Returns a new instance of Printer.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/specjour/printer.rb', line 10 def initialize @host = "0.0.0.0" @server_socket = TCPServer.new(@host, RANDOM_PORT) @port = @server_socket.addr[1] @profiler = {} @clients = {} @tests_to_run = [] @example_size = 0 self.examples_complete = 0 end |
Instance Attribute Details
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
7 8 9 |
# File 'lib/specjour/printer.rb', line 7 def clients @clients end |
#example_size ⇒ Object
Returns the value of attribute example_size.
8 9 10 |
# File 'lib/specjour/printer.rb', line 8 def example_size @example_size end |
#examples_complete ⇒ Object
Returns the value of attribute examples_complete.
8 9 10 |
# File 'lib/specjour/printer.rb', line 8 def examples_complete @examples_complete end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/specjour/printer.rb', line 7 def port @port end |
#profiler ⇒ Object
Returns the value of attribute profiler.
8 9 10 |
# File 'lib/specjour/printer.rb', line 8 def profiler @profiler end |
#tests_to_run ⇒ Object
Returns the value of attribute tests_to_run.
8 9 10 |
# File 'lib/specjour/printer.rb', line 8 def tests_to_run @tests_to_run end |
Instance Method Details
#exit_status ⇒ Object
47 48 49 |
# File 'lib/specjour/printer.rb', line 47 def exit_status reporters.all? {|r| r.exit_status == true} end |
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/specjour/printer.rb', line 21 def start fds = [@server_socket] catch(:stop) do while true reads = select(fds).first reads.each do |socket_being_read| if socket_being_read == @server_socket client_socket = @server_socket.accept fds << client_socket clients[client_socket] = Connection.wrap(client_socket) elsif socket_being_read.eof? socket_being_read.close fds.delete(socket_being_read) clients.delete(socket_being_read) disconnecting else serve(clients[socket_being_read]) end end end end ensure stopping fds.each {|c| c.close} end |