Class: Racket::Application

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

Overview

Racket main application class.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.routerObject (readonly)

Returns the value of attribute router.



25
26
27
# File 'lib/racket/application.rb', line 25

def router
  @router
end

.settingsObject (readonly)

Returns the value of attribute settings.



25
26
27
# File 'lib/racket/application.rb', line 25

def settings
  @settings
end

Class Method Details

.apply_settings(settings) ⇒ Object

Applies settings.



37
38
39
40
# File 'lib/racket/application.rb', line 37

def self.apply_settings(settings)
  fail 'Application has already been initialized!' if @settings
  @settings = Settings::Application.new(settings)
end

.call(env) ⇒ Array

Called whenever Rack sends a request to the application.

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array)

    A Rack response array



52
53
54
# File 'lib/racket/application.rb', line 52

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

.defaultClass

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

Returns:

  • (Class)


76
77
78
# File 'lib/racket/application.rb', line 76

def self.default
  init
end

.dev_mode?true|false

Returns whether the application runs in dev mode.

Returns:

  • (true|false)


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

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.

Parameters:

  • controller (Class)
  • action (Symbol) (defaults to: nil)
  • params (Array)

Returns:

  • (String)


69
70
71
# File 'lib/racket/application.rb', line 69

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.

Parameters:

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

Returns:

  • nil



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

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



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

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

.reloadnil

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

Returns:

  • (nil)


153
154
155
156
# File 'lib/racket/application.rb', line 153

def self.reload
  setup_routes
  @view_manager = nil
end

.require(*args) ⇒ nil

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

Parameters:

  • args (Object)

Returns:

  • (nil)


162
163
164
# File 'lib/racket/application.rb', line 162

def self.require(*args)
  (::Kernel.require Utils.build_path(*args)) && nil
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.



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.

Parameters:

  • settings (Hash)

Returns:

  • (Class)


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

def self.using(settings)
  init(settings)
end

.view_managerRacket::ViewManager

Returns the view cache of the currently running application.

Returns:



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