Class: Clumsy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/clumsy/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_file) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
# File 'lib/clumsy/server.rb', line 5

def initialize(test_file)
  @test_file                = test_file
  @inbound_requests         = Array.new
  @inbound_request_strings  = Array.new
  @app                      = nil
end

Instance Attribute Details

#inbound_requestsObject (readonly)

Returns the value of attribute inbound_requests.



3
4
5
# File 'lib/clumsy/server.rb', line 3

def inbound_requests
  @inbound_requests
end

Instance Method Details

#did_receive_request(request_string) ⇒ Object



27
28
29
# File 'lib/clumsy/server.rb', line 27

def did_receive_request(request_string)
  @inbound_request_strings.include?(request_string)
end

#start!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/clumsy/server.rb', line 12

def start!
  app = Proc.new do |env|
    request   = Clumsy::Request.new(env)
    response  = Clumsy::Response.new(request, @test_file)
    @inbound_requests << request
    @inbound_request_strings << request.to_s

    response.send_response
  end

  Thread.new do
    server = Rack::Handler::WEBrick.run app
  end
end