Parent

Camping::Server

Constants

SOURCE
TEMPLATE

Public Class Methods

new(*) click to toggle source
# File lib/camping/server.rb, line 98
def initialize(*)
  super
  @reloader = Camping::Reloader.new
  @reloader.on_reload 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 164
def app
  self
end
call(env) click to toggle source
# File lib/camping/server.rb, line 168
def call(env)
  reload!
  apps = @reloader.apps

  case apps.length
  when 0
    index_page(apps)
  when 1
    apps.values.first.call(env)
  else
    apps.each do |name, app|
      mount = name.to_s.downcase
      case env["PATH_INFO"]
      when %{^/#{mount}}
        env["SCRIPT_NAME"] = env["SCRIPT_NAME"] + $&
        env["PATH_INFO"] = $'
        return app.call(env)
      when %{^/code/#{mount}}
        return [200, {'Content-Type' => 'text/plain', 'X-Sendfile' => @reloader.script(app).file}, []]
      end
    end
    
    index_page(apps)
  end
end
default_options() click to toggle source
# File lib/camping/server.rb, line 119
def default_options
  super.merge({
    :Port => 3301,
    :database => Options::DB
  })
end
find_scripts() click to toggle source
# File lib/camping/server.rb, line 148
def find_scripts
  scripts = options[:scripts].map do |path|
    if File.file?(path)
      path
    elsif File.directory?(path)
      Dir[File.join(path, '*.rb')]
    end
  end.flatten.compact
      
  @reloader.update(*scripts)
end
index_page(apps) click to toggle source
# File lib/camping/server.rb, line 194
def index_page(apps)
  [200, {'Content-Type' => 'text/html'}, [TEMPLATE.result(binding)]]
end
middleware() click to toggle source
# File lib/camping/server.rb, line 126
def middleware
  h = super
  h["development"].unshift [XSendfile]
  h
end
opt_parser() click to toggle source
# File lib/camping/server.rb, line 115
def opt_parser
  Options.new
end
reload!() click to toggle source
# File lib/camping/server.rb, line 160
def reload!
  find_scripts
end
start() click to toggle source
# File lib/camping/server.rb, line 132
def start
  if options[:server] == "console"
    puts "** Starting console"
    reload!
    this = self
    eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { this.reload!; nil }
    ARGV.clear
    IRB.start
    exit
  else
    name = server.name[/\w+$/]
    puts "** Starting #{name} on #{options[:Host]}:#{options[:Port]}"
    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.