Class: N::App::ScriptHandler
- Inherits:
-
Handler
- Object
- ServerFilter
- Handler
- N::App::ScriptHandler
- Defined in:
- lib/n/app/handlers.rb
Overview
Script Handler
Base handler for scripts.
Direct Known Subclasses
Constant Summary collapse
- @@compiled_script_cache =
cache the compiled page scripts to optimize future references. use a thread safe cache.
N::SafeHash.new()
- @@compile_sync =
dont allow 2 threads to compile the same script. In fact dont allow two threads to compile in parallel.
Sync.new
Instance Attribute Summary
Attributes inherited from ServerFilter
Instance Method Summary collapse
-
#compile_script(script) ⇒ Object
the compiler returns a singleton class customized for rendering the input script.
- #compiled_script_cache ⇒ Object
-
#log_error(request, ex) ⇒ Object
Log a rendering error.
-
#overload_path(path) ⇒ Object
Overload the path.
Methods inherited from Handler
Methods inherited from ServerFilter
#<<, #initialize, #process, #process_next
Constructor Details
This class inherits a constructor from N::ServerFilter
Instance Method Details
#compile_script(script) ⇒ Object
the compiler returns a singleton class customized for rendering the input script. The original idea was to define render() as a static method and return the class, but we will use a singleton object to keep custom data structures (sub-page-graph, metrics, etc)
script_path is used as key in the Dynamic class creation and for caching
Design:
we use __ for out too to avoid nasty collisions.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/n/app/handlers.rb', line 79 def compile_script(script) compiled_script = nil # dont allow 2 threads to compile the same script. In fact dont # allow two threads to compile in parallel. # gmosx: SOS this eval assigns the variable compiled_script! @@compile_sync.synchronize { eval(script) } return compiled_script end |
#compiled_script_cache ⇒ Object
92 93 94 |
# File 'lib/n/app/handlers.rb', line 92 def compiled_script_cache return @@compiled_script_cache end |
#log_error(request, ex) ⇒ Object
Log a rendering error
98 99 100 101 102 103 104 |
# File 'lib/n/app/handlers.rb', line 98 def log_error(request, ex) request.log_error "--------" request.log_error "#{request.path}:" request.log_error "#{ex.class}: #{ex}" request.log_error ex.backtrace() raise ScriptHandlerError.new(0, "error") end |
#overload_path(path) ⇒ Object
Overload the path. FIXME: better name and much better documentation.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/n/app/handlers.rb', line 57 def overload_path(path) path.gsub!(/\/\//, '/') if ::File.exists?("#$root_dir/#{path}") return path else $log.debug "OVERLOAD: '#{path}' -> 'p/#{path}'" if $DBG return "p/#{path}" end end |