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 puma 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.



57
58
59
# File 'lib/tipsy/server.rb', line 57

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



49
50
51
52
53
54
# File 'lib/tipsy/server.rb', line 49

def banner(server, port)
  puts ""
  Tipsy.logger.info " Tipsy #{Tipsy::VERSION}", :green
  Tipsy.logger.info " Started from #{Tipsy.root}"
  Tipsy.logger.info " using #{server}, port #{port}"
end

.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
41
42
43
44
45
46
47
# File 'lib/tipsy/server.rb', line 18

def run!(app, options)
  begin
    handler = Rack::Handler.get('thin')
    handler.run app, options do |server|
      banner("Thin (#{Thin::VERSION::STRING})", options[:Port])
      puts "-----------------------------------------------------------------"
      puts ""
    end
    exit(0)
  rescue LoadError
    begin
      handler = Rack::Handler.get('puma')
      handler.run app, options do |server|
        banner("Puma (#{Puma::Const::PUMA_VERSION})", options[:Port])
        puts "-----------------------------------------------------------------"
        puts ""
      end
      exit(0)
    rescue LoadError
      handler = Rack::Handler.get('webrick')
      handler.run app, options do |server|
        banner("Webrick", options[:Port])
        puts " To use Puma or Thin (recommended), add them to your Gemfile"
        puts "-----------------------------------------------------------------"
        puts ""
        trap("INT"){ server.shutdown }
      end
    end
  end
end

Instance Method Details

#call(env) ⇒ Object



61
62
63
64
65
66
# File 'lib/tipsy/server.rb', line 61

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