Class: Microengine::Dispatcher
- Inherits:
-
Object
- Object
- Microengine::Dispatcher
- Defined in:
- lib/dispatcher.rb
Overview
Use FastCGI to return XHTML by HTTP request
Instance Attribute Summary collapse
-
#admin ⇒ Object
writeonly
Sets the attribute admin.
-
#cache ⇒ Object
writeonly
Sets the attribute cache.
-
#config ⇒ Object
writeonly
Sets the attribute config.
-
#logger ⇒ Object
writeonly
Sets the attribute logger.
Instance Method Summary collapse
-
#language(http, available) ⇒ Object
Select best language for user.
-
#not_found(http) ⇒ Object
Forward to 404 error.
-
#run ⇒ Object
Start FastCGI.
Instance Attribute Details
#admin=(value) ⇒ Object (writeonly)
Sets the attribute admin
30 31 32 |
# File 'lib/dispatcher.rb', line 30 def admin=(value) @admin = value end |
#cache=(value) ⇒ Object (writeonly)
Sets the attribute cache
29 30 31 |
# File 'lib/dispatcher.rb', line 29 def cache=(value) @cache = value end |
#config=(value) ⇒ Object (writeonly)
Sets the attribute config
27 28 29 |
# File 'lib/dispatcher.rb', line 27 def config=(value) @config = value end |
#logger=(value) ⇒ Object (writeonly)
Sets the attribute logger
28 29 30 |
# File 'lib/dispatcher.rb', line 28 def logger=(value) @logger = value end |
Instance Method Details
#language(http, available) ⇒ Object
Select best language for user
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dispatcher.rb', line 70 def language(http, available) # Language selected manually if not http.get['lang'].nil? return http.get['lang'] if available.include? http.get['lang'] elsif http.['lang'] return http.['lang'] if available.include? http.['lang'] end # Select user language http.langs.each do |lang| lang.downcase! return lang if available.include? lang end # Select any language if available.include? @config['default_language'] @config['default_language'] else available.first end end |
#not_found(http) ⇒ Object
Forward to 404 error
63 64 65 66 67 |
# File 'lib/dispatcher.rb', line 63 def not_found(http) http.status = '404 Not Found' http << @cache.get('/404/', language(http, @cache.langs['/404/'])) http.finish end |
#run ⇒ Object
Start FastCGI
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dispatcher.rb', line 33 def run FCGI.each do |request| http = HTTP.new(request) if @admin.dispatch(http) request.finish next else langs = @cache.langs[http.url] if langs.nil? not_found http request.finish next end if http.get['lang'] http. 'lang', http.get['lang'], 30 unless langs.include? http.get['lang'] http.redirect http.url request.finish next end end http << @cache.get(http.url, language(http, langs)) request.finish end end end |