Class: Racket::Application

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

Overview

Racket main application class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Class

Initializes the Racket application.

Parameters:

  • settings (Hash) (defaults to: {})


43
44
45
46
47
# File 'lib/racket/application.rb', line 43

def initialize(settings = {})
  @registry = Utils::Application::RegistryBuilder.new(settings).registry
  @registry.handler_stack # Makes sure all plugins and helpers are loaded before any controllers
  load_controllers
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



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

def registry
  @registry
end

Class Method Details

.defaultClass

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

Returns:

  • (Class)


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

def self.default
  new
end

.using(settings) ⇒ Class

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

Parameters:

  • settings (Hash)

Returns:

  • (Class)


33
34
35
# File 'lib/racket/application.rb', line 33

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

Instance 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



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

def call(env)
  @registry.handler_stack.call(env.dup)
end

#dev_mode?true|false

Returns whether the application runs in dev mode.

Returns:

  • (true|false)


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

def dev_mode?
  @registry.application_settings.mode == :dev
end

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

Sends a message to the logger.

Parameters:

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

Returns:

  • nil



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

def inform_all(message, level = :info)
  @registry.application_logger.inform_all(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



78
79
80
# File 'lib/racket/application.rb', line 78

def inform_dev(message, level = :debug)
  @registry.application_logger.inform_dev(message, level)
end

#kernel_requireObject



82
# File 'lib/racket/application.rb', line 82

alias kernel_require require

#require(*args) ⇒ nil

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

Parameters:

  • args (Object)

Returns:

  • (nil)


88
89
90
# File 'lib/racket/application.rb', line 88

def require(*args)
  (kernel_require @registry.utils.build_path(*args)) && nil
end