Class: Rack::Server

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

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Server

Returns a new instance of Server.



88
89
90
# File 'lib/rack/server.rb', line 88

def initialize(options = nil)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



86
87
88
# File 'lib/rack/server.rb', line 86

def options
  @options
end

Class Method Details

.middlewareObject



119
120
121
122
123
124
125
126
# File 'lib/rack/server.rb', line 119

def self.middleware
  @middleware ||= begin
    m = Hash.new {|h,k| h[k] = []}
    m["deployment"].concat  [lambda {|server| server.server =~ /CGI/ ? nil : [Rack::CommonLogger, $stderr] }]
    m["development"].concat m["deployment"] + [[Rack::ShowExceptions], [Rack::Lint]]
    m
  end
end

.startObject



82
83
84
# File 'lib/rack/server.rb', line 82

def self.start
  new.start
end

Instance Method Details

#appObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rack/server.rb', line 107

def app
  @app ||= begin
    if !::File.exist? options[:config]
      abort "configuration #{options[:config]} not found"
    end

    app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
    self.options.merge! options
    app
  end
end

#default_optionsObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/rack/server.rb', line 96

def default_options
  {
    :environment => "development",
    :pid         => nil,
    :Port        => 9292,
    :Host        => "0.0.0.0",
    :AccessLog   => [],
    :config      => "config.ru"
  }
end

#middlewareObject



128
129
130
# File 'lib/rack/server.rb', line 128

def middleware
  self.class.middleware
end

#serverObject



158
159
160
# File 'lib/rack/server.rb', line 158

def server
  @_server ||= Rack::Handler.get(options[:server]) || Rack::Handler.default
end

#startObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rack/server.rb', line 132

def start
  if options[:debug]
    $DEBUG = true
    require 'pp'
    p options[:server]
    pp wrapped_app
    pp app
  end

  if options[:warn]
    $-w = true
  end

  if includes = options[:include]
    $LOAD_PATH.unshift *includes
  end

  if library = options[:require]
    require library
  end

  daemonize_app if options[:daemonize]
  write_pid if options[:pid]
  server.run wrapped_app, options
end