Class: Rage::Configuration
- Inherits:
-
Object
- Object
- Rage::Configuration
- Defined in:
- lib/rage/configuration.rb
Overview
Configuration class for Rage framework.
Use Rage.configure to access and modify the configuration.
Example:
Rage.configure do
config.log_level = :warn
config.server.port = 8080
end
Transient Settings
The settings described in this section should be configured using environment variables and are either temporary or will become the default in the future.
-
RAGE_DISABLE_IO_WRITE - disables the
io_writehook to fix the “zero-length iov” error on Ruby < 3.3. -
RAGE_DISABLE_AR_POOL_PATCH - disables the
ActiveRecord::ConnectionPoolpatch and makes Rage use the original ActiveRecord implementation. -
RAGE_DISABLE_AR_WEAK_CONNECTIONS - instructs Rage to not reuse Active Record connections between different fibers. Only applies to Active Record < 7.2.
Defined Under Namespace
Classes: Cable, Deferred, LogContext, LogTags, Middleware, OpenAPI, PublicFileServer, Server
General Configuration collapse
-
#after_initialize(&block) ⇒ Object
Schedule a block of code to run after Rage has finished loading the application code.
-
#fallback_secret_key_base ⇒ Array<String>
Returns the fallback secret key base(s) used for decrypting cookies encrypted with old secrets.
-
#fallback_secret_key_base=(key) ⇒ Object
Set one or several old secrets that need to be rotated.
-
#log_formatter ⇒ #call?
Returns the log formatter used by Rage.
-
#log_formatter=(formatter) ⇒ Object
Set the log formatter used by Rage.
-
#log_level ⇒ Integer?
Returns the log level used by Rage.
-
#log_level=(level) ⇒ Object
Set the log level used by Rage.
-
#logger ⇒ Rage::Logger?
Returns the logger used by Rage.
-
#logger=(logger) ⇒ Object
Set the logger used by Rage.
-
#secret_key_base ⇒ String?
Returns the secret key base used for encrypting cookies.
-
#secret_key_base=(key) ⇒ Object
The secret key base is used as the input secret to the application’s key generator, which is used to encrypt cookies.
Middleware Configuration collapse
-
#middleware ⇒ Rage::Configuration::Middleware
Allows configuring the middleware stack used by Rage.
Server Configuration collapse
-
#server ⇒ Rage::Configuration::Server
Allows configuring the built-in Rage server.
Static File Server collapse
-
#public_file_server ⇒ Rage::Configuration::PublicFileServer
Allows configuring the static file server used by Rage.
Cable Configuration collapse
-
#cable ⇒ Rage::Configuration::Cable
Allows configuring Cable settings.
OpenAPI Configuration collapse
-
#openapi ⇒ Rage::Configuration::OpenAPI
Allows configuring OpenAPI settings.
Deferred Configuration collapse
-
#deferred ⇒ Rage::Configuration::Deferred
Allows configuring Deferred settings.
Logging Context and Tags Configuration collapse
-
#log_context ⇒ Rage::Configuration::LogContext
Allows configuring custom log context objects that will be included in every log entry.
-
#log_tags ⇒ Rage::Configuration::LogTags
Allows configuring custom log tags that will be included in every log entry.
Instance Method Details
#after_initialize(&block) ⇒ Object
Schedule a block of code to run after Rage has finished loading the application code. Use this to reference application-level constants during the initialization process.
139 140 141 |
# File 'lib/rage/configuration.rb', line 139 def after_initialize(&block) push_hook(block, :after_initialize) end |
#cable ⇒ Rage::Configuration::Cable
Allows configuring Cable settings.
171 172 173 |
# File 'lib/rage/configuration.rb', line 171 def cable @cable ||= Cable.new end |
#deferred ⇒ Rage::Configuration::Deferred
Allows configuring Deferred settings.
187 188 189 |
# File 'lib/rage/configuration.rb', line 187 def deferred @deferred ||= Deferred.new end |
#fallback_secret_key_base ⇒ Array<String>
Returns the fallback secret key base(s) used for decrypting cookies encrypted with old secrets.
130 131 132 |
# File 'lib/rage/configuration.rb', line 130 def fallback_secret_key_base Array(@fallback_secret_key_base || ENV["FALLBACK_SECRET_KEY_BASE"]) end |
#fallback_secret_key_base=(key) ⇒ Object
Set one or several old secrets that need to be rotated. Can accept a single key or an array of keys. Rage will fall back to the FALLBACK_SECRET_KEY_BASE environment variable if this is not set.
124 125 126 |
# File 'lib/rage/configuration.rb', line 124 def fallback_secret_key_base=(key) @fallback_secret_key_base = key end |
#log_context ⇒ Rage::Configuration::LogContext
Allows configuring custom log context objects that will be included in every log entry.
195 196 197 |
# File 'lib/rage/configuration.rb', line 195 def log_context @log_context ||= LogContext.new end |
#log_formatter ⇒ #call?
Returns the log formatter used by Rage.
79 80 81 |
# File 'lib/rage/configuration.rb', line 79 def log_formatter @log_formatter end |
#log_formatter=(formatter) ⇒ Object
Set the log formatter used by Rage. Built in options include Rage::TextFormatter and Rage::JSONFormatter.
91 92 93 94 |
# File 'lib/rage/configuration.rb', line 91 def log_formatter=(formatter) raise ArgumentError, "Custom log formatter should respond to `#call`" unless formatter.respond_to?(:call) @log_formatter = formatter end |
#log_level ⇒ Integer?
Returns the log level used by Rage.
98 99 100 |
# File 'lib/rage/configuration.rb', line 98 def log_level @log_level end |
#log_level=(level) ⇒ Object
Set the log level used by Rage.
106 107 108 |
# File 'lib/rage/configuration.rb', line 106 def log_level=(level) @log_level = level.is_a?(Symbol) ? Logger.const_get(level.to_s.upcase) : level end |
#log_tags ⇒ Rage::Configuration::LogTags
Allows configuring custom log tags that will be included in every log entry.
201 202 203 |
# File 'lib/rage/configuration.rb', line 201 def @log_tags ||= LogTags.new end |
#logger ⇒ Rage::Logger?
Returns the logger used by Rage.
39 40 41 |
# File 'lib/rage/configuration.rb', line 39 def logger @logger end |
#logger=(logger) ⇒ Object #logger=(callable) ⇒ Object #logger=(nil) ⇒ Object
Set the logger used by Rage. Accepts a logger object that implements the #debug, #info, #warn, #error, #fatal, and #unknown methods, or nil. If set to nil, logging will be disabled. Rage.logger always returns an instance of Rage::Logger, but if you provide a custom object, it will be used internally by Rage.logger.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rage/configuration.rb', line 65 def logger=(logger) @logger = if logger.nil? || logger.is_a?(Rage::Logger) logger elsif Rage::Logger::METHODS_MAP.keys.all? { |method| logger.respond_to?(method) } Rage::Logger.new(Rage::Logger::External::Static[logger]) elsif logger.respond_to?(:call) Rage::Logger.new(Rage::Logger::External::Dynamic[logger]) else raise ArgumentError, "Invalid logger: must be an instance of `Rage::Logger`, respond to `#call`, or implement all standard Ruby Logger methods (`#debug`, `#info`, `#warn`, `#error`, `#fatal`, `#unknown`)" end end |
#middleware ⇒ Rage::Configuration::Middleware
Allows configuring the middleware stack used by Rage.
147 148 149 |
# File 'lib/rage/configuration.rb', line 147 def middleware @middleware ||= Middleware.new end |
#openapi ⇒ Rage::Configuration::OpenAPI
Allows configuring OpenAPI settings.
179 180 181 |
# File 'lib/rage/configuration.rb', line 179 def openapi @openapi ||= OpenAPI.new end |
#public_file_server ⇒ Rage::Configuration::PublicFileServer
Allows configuring the static file server used by Rage.
163 164 165 |
# File 'lib/rage/configuration.rb', line 163 def public_file_server @public_file_server ||= PublicFileServer.new end |
#secret_key_base ⇒ String?
Returns the secret key base used for encrypting cookies.
118 119 120 |
# File 'lib/rage/configuration.rb', line 118 def secret_key_base @secret_key_base || ENV["SECRET_KEY_BASE"] end |
#secret_key_base=(key) ⇒ Object
The secret key base is used as the input secret to the application’s key generator, which is used to encrypt cookies. Rage will fall back to the SECRET_KEY_BASE environment variable if this is not set.
112 113 114 |
# File 'lib/rage/configuration.rb', line 112 def secret_key_base=(key) @secret_key_base = key end |
#server ⇒ Rage::Configuration::Server
Allows configuring the built-in Rage server.
155 156 157 |
# File 'lib/rage/configuration.rb', line 155 def server @server ||= Server.new end |