Class: Racket::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/racket/application.rb

Overview

Racket main application class.

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Array

Called whenever Rack sends a request to the application.

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array)

    A Rack response array



59
60
61
# File 'lib/racket/application.rb', line 59

def self.call(env)
  application.call(env.dup)
end

.default(reboot = false) ⇒ Class

Initializes a new Racket::Application object with default options.

Parameters:

  • reboot (true|false) (defaults to: false)

Returns:

  • (Class)


113
114
115
# File 'lib/racket/application.rb', line 113

def self.default(reboot = false)
  init({}, reboot)
end

.dev_mode?true|false

Returns whether the application runs in dev mode.

Returns:

  • (true|false)


95
96
97
# File 'lib/racket/application.rb', line 95

def self.dev_mode?
  @options[:mode] == :dev
end

.get_route(controller, action, params) ⇒ String

Returns a route to the specified controller/action/parameter combination.

Parameters:

  • controller (Class)
  • action (Symbol)
  • params (Array)

Returns:

  • (String)


105
106
107
# File 'lib/racket/application.rb', line 105

def self.get_route(controller, action, params)
  @router.get_route(controller, action, params)
end

.inform_all(message, level = :info) ⇒ Object

Sends a message to the logger.

Parameters:

  • message (String)
  • level (Symbol) (defaults to: :info)

Returns:

  • nil



131
132
133
# File 'lib/racket/application.rb', line 131

def self.inform_all(message, level = :info)
  inform(message, level)
end

.inform_dev(message, level = :debug) ⇒ Object

Sends a message to the logger, but only if the application is running in dev mode.

Parameters:

  • message (String)
  • level (Symbol) (defaults to: :debug)

Returns:

  • nil



140
141
142
# File 'lib/racket/application.rb', line 140

def self.inform_dev(message, level = :debug)
  (inform(message, level) if dev_mode?) && nil
end

.optionsHash

Returns options for the currently running Racket::Application.

Returns:

  • (Hash)


188
189
190
# File 'lib/racket/application.rb', line 188

def self.options
  @options
end

.reloadnil

Reloads the application, making any changes to the controller configuration visible to the application.

Returns:

  • (nil)


196
197
198
199
# File 'lib/racket/application.rb', line 196

def self.reload
  setup_routes
  @view_cache = nil
end

.require(*args) ⇒ nil

Requires a file using the current application directory as a base path.

Parameters:

  • args (Object)

Returns:

  • (nil)


205
206
207
# File 'lib/racket/application.rb', line 205

def self.require(*args)
  (::Kernel.require Utils.build_path(*args)) && nil
end

.routerRacket::Router

Returns the router associated with the currenntly running Racket::Application.

Returns:



212
213
214
# File 'lib/racket/application.rb', line 212

def self.router
  @router
end

.serve_static_file(env) ⇒ Array|nil

Serves a static file (if Racket is configured to serve static files).

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array|nil)

    A Rack response array if Rack::File handled the file, nil otherwise.



220
221
222
223
# File 'lib/racket/application.rb', line 220

def self.serve_static_file(env)
  return nil if @static_server.nil?
  @static_server.call(env)
end

.using(options, reboot = false) ⇒ Class

Initializes a new Racket::Application object with options specified by options.

Parameters:

  • options (Hash)
  • reboot (true|false) (defaults to: false)

Returns:

  • (Class)


248
249
250
# File 'lib/racket/application.rb', line 248

def self.using(options, reboot = false)
  init(options, reboot)
end

.view_cacheViewCache

Returns the view cache of the currently running application.

Returns:



255
256
257
# File 'lib/racket/application.rb', line 255

def self.view_cache
  @view_cache ||= ViewCache.new(@options[:layout_dir], @options[:view_dir])
end