Class: Cuca::App
- Inherits:
-
Object
- Object
- Cuca::App
- Defined in:
- lib/cuca/app.rb
Overview
Cuca Application
A Cuca::App object will be created directly by the dispatcher - which again is the direct cgi or fastcgi script that get run by the webserver. Normally you just create a Cuca::App object and run the cgicall function with optional with a cgi object as paramenter. Before doing that you must set $cuca_path to the root of your appication structure.
Defined Under Namespace
Classes: Config
Constant Summary collapse
- @@app_config =
Config.new
- @@oncall =
[]
Instance Attribute Summary collapse
-
#cgi ⇒ Object
readonly
Returns the value of attribute cgi.
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#urlmap ⇒ Object
readonly
Returns the value of attribute urlmap.
Class Method Summary collapse
- .config ⇒ Object
- .configure {|@@app_config| ... } ⇒ Object
-
.oncall(&block) ⇒ Object
if you should need to get notified on every (cgi)-call you can register a proc here.
Instance Method Summary collapse
- #cgicall ⇒ Object
-
#initialize(cgi = nil) ⇒ App
constructor
A new instance of App.
-
#load_support_files ⇒ Object
:nodoc:.
Constructor Details
#initialize(cgi = nil) ⇒ App
Returns a new instance of App.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/cuca/app.rb', line 204 def initialize(cgi = nil) $cgi = cgi || CGI.new @cgi = $cgi mk_config @logger = Logger.new(@conf['LOG_PATH'] + "/messages") $logger = @logger $conf = @conf $app = self rescue RuntimeError => e @cgi.out { "Error initializing the app: #{$!}" } end |
Instance Attribute Details
#cgi ⇒ Object (readonly)
Returns the value of attribute cgi.
80 81 82 |
# File 'lib/cuca/app.rb', line 80 def cgi @cgi end |
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
80 81 82 |
# File 'lib/cuca/app.rb', line 80 def conf @conf end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
80 81 82 |
# File 'lib/cuca/app.rb', line 80 def logger @logger end |
#urlmap ⇒ Object (readonly)
Returns the value of attribute urlmap.
80 81 82 |
# File 'lib/cuca/app.rb', line 80 def urlmap @urlmap end |
Class Method Details
.config ⇒ Object
91 92 93 |
# File 'lib/cuca/app.rb', line 91 def self.config @@app_config end |
.configure {|@@app_config| ... } ⇒ Object
87 88 89 |
# File 'lib/cuca/app.rb', line 87 def self.configure yield @@app_config end |
.oncall(&block) ⇒ Object
if you should need to get notified on every (cgi)-call you can register a proc here. The SessionFlash/Page is makeing use of this
98 99 100 |
# File 'lib/cuca/app.rb', line 98 def self.oncall(&block) @@oncall << block end |
Instance Method Details
#cgicall ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/cuca/app.rb', line 242 def cgicall script = @conf['SCRIPT'] # # 1st priority: Serve a file if it exists in the 'public' folder # file = @conf['PUBLIC_PATH'] + '/' + @conf['PATH_INFO'] if File.exists?(file) && File.ftype(file) == 'file' then require 'cuca/mimetypes' mt = MimeTypes.new f = File.new(file) extension = file.scan(/.*\.(.*)$/)[0][0] if file.include?('.') extension ||= 'html' mime = mt[extension] || 'text/html' @cgi.out(mime) { f.read } f.close return end # # 2nd: Check if we have a script for requested action # if (!File.exists?(script)) then @cgi.out { "Script not found: #{script}" } return end # Notify who needs to know @@oncall.each { |p| p.call } # 3rd: Load additional files load_support_files # 4th: Now let's run the actual page script code controller_class_name = @conf['ACTION'].capitalize+"Controller" # Clear all hints Widget::clear_hints() # Load the code of the action into the module controller_module = @urlmap.action_module controller_module.module_eval(File.open(script).read, script) unless \ controller_module.const_defined?(controller_class_name.intern) # Catch a common user error if !controller_module.const_defined?(controller_class_name.intern) then @cgi.out { "Could not find #{controller_class_name} defined in #{script}" } return end # # Load the controller # begin result = Sandbox.run(controller_class_name, @urlmap.action_module, @conf['ASSIGNS'], $cgi.request_method, @conf['SUBCALL']) @cgi.out('type' => 'text/html') {result} rescue Cuca::ApplicationException => e err = "<b>Application Error: #{e}</b><br/>" e.backtrace.each do |b| err +="<br/>#{b}" end @cgi.out('status' => 'SERVER_ERROR') { err } return rescue => e err = "<b>System Error: #{e}</b><br/>" e.backtrace.each do |b| err +="<br/>#{b}" end @cgi.out('status' => 'SERVER_ERROR') { err } return end end |
#load_support_files ⇒ Object
:nodoc:
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/cuca/app.rb', line 222 def load_support_files # :nodoc: # $stderr.puts "======== load support files =========" # $stderr.puts "Inc Dir: #{App::config['include_directories'].inspect}" # $stderr.puts "Path tr: #{@conf['PATH_TREE'].inspect}" # $stderr.puts "=====================================" base_path = @conf['APP_PATH'] @conf['PATH_TREE'].each do |t| base_path << "/#{t}" (App::config['include_directories'] || []).each do |id| include_files "#{base_path}/#{id}" end end # (App::config['include_directories'] || []).each do |id| # @conf['PATH_TREE'].each { |t| include_files @conf['APP_PATH'] + '/'+t+"/#{id}/"} # end end |