Rack::Server
# File lib/camping/server.rb, line 98 98: def initialize(*) 99: super 100: @reloader = Camping::Reloader.new 101: @reloader.on_reload do |app| 102: if !app.options.has_key?(:dynamic_templates) 103: app.options[:dynamic_templates] = true 104: end 105: 106: if !Camping::Models.autoload?(:Base) && options[:database] 107: Camping::Models::Base.establish_connection( 108: :adapter => 'sqlite3', 109: :database => options[:database] 110: ) 111: end 112: end 113: end
# File lib/camping/server.rb, line 168 168: def call(env) 169: reload! 170: apps = @reloader.apps 171: 172: case apps.length 173: when 0 174: index_page(apps) 175: when 1 176: apps.values.first.call(env) 177: else 178: apps.each do |name, app| 179: mount = name.to_s.downcase 180: case env["PATH_INFO"] 181: when %{^/#{mount}} 182: env["SCRIPT_NAME"] = env["SCRIPT_NAME"] + $& 183: env["PATH_INFO"] = $' 184: return app.call(env) 185: when %{^/code/#{mount}} 186: return [200, {'Content-Type' => 'text/plain', 'X-Sendfile' => @reloader.script(app).file}, []] 187: end 188: end 189: 190: index_page(apps) 191: end 192: end
# File lib/camping/server.rb, line 119 119: def default_options 120: super.merge({ 121: :Port => 3301, 122: :database => Options::DB 123: }) 124: end
# File lib/camping/server.rb, line 148 148: def find_scripts 149: scripts = options[:scripts].map do |path| 150: if File.file?(path) 151: path 152: elsif File.directory?(path) 153: Dir[File.join(path, '*.rb')] 154: end 155: end.flatten.compact 156: 157: @reloader.update(*scripts) 158: end
# File lib/camping/server.rb, line 194 194: def index_page(apps) 195: [200, {'Content-Type' => 'text/html'}, [TEMPLATE.result(binding)]] 196: end
# File lib/camping/server.rb, line 126 126: def middleware 127: h = super 128: h["development"].unshift [XSendfile] 129: h 130: end
# File lib/camping/server.rb, line 115 115: def opt_parser 116: Options.new 117: end
# File lib/camping/server.rb, line 160 160: def reload! 161: find_scripts 162: end
# File lib/camping/server.rb, line 132 132: def start 133: if options[:server] == "console" 134: puts "** Starting console" 135: reload! 136: this = self 137: eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { this.reload!; nil } 138: ARGV.clear 139: IRB.start 140: exit 141: else 142: name = server.name[/\w+$/] 143: puts "** Starting #{name} on #{options[:Host]}:#{options[:Port]}" 144: super 145: end 146: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.