Class: Racket::Application
- Inherits:
-
Object
- Object
- Racket::Application
- Defined in:
- lib/racket/application.rb
Overview
Racket main application class.
Class Attribute Summary collapse
-
.router ⇒ Object
readonly
Returns the value of attribute router.
-
.settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
-
.call(env) ⇒ Array
Called whenever Rack sends a request to the application.
-
.default ⇒ Class
Initializes a new Racket::Application object with default settings.
-
.dev_mode? ⇒ true|false
Returns whether the application runs in dev mode.
-
.get_route(controller, action = nil, *params) ⇒ String
Returns a route to the specified controller/action/parameter combination.
-
.inform_all(message, level = :info) ⇒ Object
Sends a message to the logger.
-
.inform_dev(message, level = :debug) ⇒ Object
Sends a message to the logger, but only if the application is running in dev mode.
-
.reload ⇒ nil
Reloads the application, making any changes to the controller configuration visible to the application.
-
.require(*args) ⇒ nil
Requires a file using the current application directory as a base path.
-
.reset! ⇒ Object
Resets Racket::Application, making it possible to run run a new application with new settings.
-
.serve_static_file(env) ⇒ Array|nil
Serves a static file (if Racket is configured to serve static files).
-
.using(settings) ⇒ Class
Initializes a new Racket::Application object with settings specified by
settings. -
.view_manager ⇒ Racket::ViewManager
Returns the view cache of the currently running application.
Class Attribute Details
.router ⇒ Object (readonly)
Returns the value of attribute router.
25 26 27 |
# File 'lib/racket/application.rb', line 25 def router @router end |
.settings ⇒ Object (readonly)
Returns the value of attribute settings.
25 26 27 |
# File 'lib/racket/application.rb', line 25 def settings @settings end |
Class Method Details
.call(env) ⇒ Array
Called whenever Rack sends a request to the application.
46 47 48 |
# File 'lib/racket/application.rb', line 46 def self.call(env) application.call(env.dup) end |
.default ⇒ Class
Initializes a new Racket::Application object with default settings.
70 71 72 |
# File 'lib/racket/application.rb', line 70 def self.default init end |
.dev_mode? ⇒ true|false
Returns whether the application runs in dev mode.
53 54 55 |
# File 'lib/racket/application.rb', line 53 def self.dev_mode? @settings.mode == :dev end |
.get_route(controller, action = nil, *params) ⇒ String
Returns a route to the specified controller/action/parameter combination.
63 64 65 |
# File 'lib/racket/application.rb', line 63 def self.get_route(controller, action = nil, *params) @router.get_route(controller, action, params) end |
.inform_all(message, level = :info) ⇒ Object
Sends a message to the logger.
89 90 91 |
# File 'lib/racket/application.rb', line 89 def self.inform_all(, level = :info) inform(, level) end |
.inform_dev(message, level = :debug) ⇒ Object
Sends a message to the logger, but only if the application is running in dev mode.
98 99 100 |
# File 'lib/racket/application.rb', line 98 def self.inform_dev(, level = :debug) (inform(, level) if dev_mode?) && nil end |
.reload ⇒ nil
Reloads the application, making any changes to the controller configuration visible to the application.
146 147 148 149 |
# File 'lib/racket/application.rb', line 146 def self.reload setup_routes @view_manager = nil end |
.require(*args) ⇒ nil
Requires a file using the current application directory as a base path.
155 156 157 |
# File 'lib/racket/application.rb', line 155 def self.require(*args) (::Kernel.require Utils.build_path(*args)) && nil end |
.reset! ⇒ Object
Remove this when Racket::Application stops beeing a singleton (if ever).
Resets Racket::Application, making it possible to run run a new application with new settings. This is a workaround for Racket::Application being a singleton, making tests harder to write,
162 163 164 |
# File 'lib/racket/application.rb', line 162 def self.reset! instance_variables.each { |ivar| instance_variable_set(ivar, nil) } end |
.serve_static_file(env) ⇒ Array|nil
Serves a static file (if Racket is configured to serve static files).
170 171 172 |
# File 'lib/racket/application.rb', line 170 def self.serve_static_file(env) @static_server ? @static_server.call(env) : nil end |
.using(settings) ⇒ Class
Initializes a new Racket::Application object with settings specified by settings.
197 198 199 |
# File 'lib/racket/application.rb', line 197 def self.using(settings) init(settings) end |
.view_manager ⇒ Racket::ViewManager
Returns the view cache of the currently running application.
204 205 206 |
# File 'lib/racket/application.rb', line 204 def self.view_manager @view_manager ||= ViewManager.new(@settings.layout_dir, @settings.view_dir) end |