class Camping::Server

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/camping/server.rb, line 98
def initialize(*)
  super
  @reloader = Camping::Reloader.new(options[:script]) do |app|
    if !app.options.has_key?(:dynamic_templates)
                  app.options[:dynamic_templates] = true
          end
          
    if !Camping::Models.autoload?(:Base) && options[:database]
      Camping::Models::Base.establish_connection(
        :adapter => 'sqlite3',
        :database => options[:database]
      )
    end
  end
end

Public Instance Methods

app() click to toggle source
# File lib/camping/server.rb, line 151
def app
  Rack::Cascade.new([Rack::File.new(public_dir), self], [405, 404, 403])
end
call(env) click to toggle source
# File lib/camping/server.rb, line 164
def call(env)
  app = current_app || raise("Could not find an app called `#{@reloader.name}`")
  app.call(env)
end
current_app() click to toggle source
# File lib/camping/server.rb, line 155
def current_app
  @reloader.reload
  apps = @reloader.apps
  return apps.values.first if apps.size == 1
  if key = apps.keys.grep(/^#{@reloader.name}$/i)[0]
    apps[key]
  end
end
default_options() click to toggle source
Calls superclass method
# File lib/camping/server.rb, line 118
def default_options
  super.merge({
    :Port => 3301,
    :database => Options::DB
  })
end
middleware() click to toggle source
Calls superclass method
# File lib/camping/server.rb, line 125
def middleware
  h = super
  h["development"] << [XSendfile]
  h
end
opt_parser() click to toggle source
# File lib/camping/server.rb, line 114
def opt_parser
  Options.new
end
public_dir() click to toggle source
# File lib/camping/server.rb, line 147
def public_dir
  File.expand_path('../public', @reloader.file)
end
start() click to toggle source
Calls superclass method
# File lib/camping/server.rb, line 131
def start
  if options[:server] == "console"
    puts "** Starting console"
    @reloader.reload!
    r = @reloader
    eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { r.reload!; nil }
    ARGV.clear
    IRB.start
    exit
  else
    name = server.name[/\w+$/]
    puts "** Starting #{name} on #{options[:Host]}:#{options[:Port]}"
    super
  end
end