Class: Tipsy::Server

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

Overview

Rack server implementation. Tipsy::Server will run any Rack::Builder compatable format. If thin or mongrel are availble, they will be used first, and in that order, with a fallback to webrick.

Defined Under Namespace

Classes: Request, Response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



43
44
45
# File 'lib/tipsy/server.rb', line 43

def initialize      
  @last_update = Time.now      
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



11
12
13
# File 'lib/tipsy/server.rb', line 11

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/tipsy/server.rb', line 11

def response
  @response
end

Class Method Details

.run!(app, options) ⇒ Object

Run the Rack::Builder application

Parameters:

  • Rack::Builder (run)

    An instance of Rack::Builder



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tipsy/server.rb', line 18

def run!(app, options)
  begin
    handler = Rack::Handler.get('thin')
    handler.run app, options do |server|
      puts "Running Tipsy with Thin (#{Thin::VERSION::STRING})."
    end
    exit(0)
  rescue LoadError
    begin
      handler = Rack::Handler.get('mongrel')
      handler.run app, options do |server|
        puts "Running Tipsy with Mongrel (#{Mongrel::Const::MONGREL_VERSION})."
      end
      exit(0)
    rescue LoadError
      handler = Rack::Handler.get('webrick')
      handler.run app, options do |server|
        puts "Running Tipsy with Webrick. To use Mongrel or Thin (recommended), add them to your Gemfile"
        trap("INT"){ server.shutdown }
      end
    end
  end
end

Instance Method Details

#call(env) ⇒ Object



47
48
49
50
51
52
# File 'lib/tipsy/server.rb', line 47

def call(env)      
  @request  = Request.new(env)
  @response = Response.new      
  result    = Tipsy::View::Base.new(@request, @response)
  result.render.to_a
end