Class: Server::Dispatcher
- Inherits:
-
Object
- Object
- Server::Dispatcher
- Defined in:
- lib/server/dispatcher.rb
Constant Summary
- WEB_ROOT =
'web_root'
Instance Method Summary (collapse)
- - (Object) dispatch(request, response, server)
- - (Object) execute_php(path, params)
- - (Object) regenerate_files_if(path, server)
Instance Method Details
- (Object) dispatch(request, response, server)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/server/dispatcher.rb', line 30 def dispatch(request, response, server) path = request.path server.log path regenerate_files_if(path, server) # Make sure the file exists and is not a directory # before attempting to open it. if File.exist?(path) && !File.directory?(path) if path.include? '.php' response.send(200, execute_php(path, request.params)) else response.send_file path end elsif File.exist?(path) && File.directory?(path) path = "#{path}/index.html" if File.exist?(path) && !File.directory?(path) response.send_301 path else response.send_404 end else response.send_404 end end |
- (Object) execute_php(path, params)
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/server/dispatcher.rb', line 7 def execute_php(path, params) params_s = '' params.each do |key, value| params_s+=key+'='+value[0]+' ' end executors = ['php', 'php-cgi', 'php-fpm'] cmd = "#{executors[0]} #{path} #{params_s}" STDERR.puts(cmd) %x[ #{cmd} ] end |
- (Object) regenerate_files_if(path, server)
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/server/dispatcher.rb', line 18 def regenerate_files_if(path, server) return unless path.include? '.html' #no html? no reload -> no regenarate server.log "#######################" server.log "# #" server.log "# Renew all files #" server.log "# #" server.log "#######################" Generator::Generator.new.generate end |