Class: Cybertrain::Config
- Inherits:
-
Object
- Object
- Cybertrain::Config
- Defined in:
- cybertrain/config.rb
Overview
The application’s settings. Defaults come from the environment (CYBERTRAIN_ENV, PORT, CYBERTRAIN_DATABASE, CYBERTRAIN_SECRET_KEY_BASE, SPINEL_WORKERS, CYBERTRAIN_HOST, CYBERTRAIN_SESSION_SAME_SITE, CYBERTRAIN_SESSION_PARTITIONED); config/app.rb then adjusts them:
Cybertrain.configure do |c| c.port = 3000 end
Read it anywhere as Cybertrain.config.
Instance Attribute Summary collapse
-
#csrf ⇒ Boolean
Whether non-GET requests must carry the CSRF token,
true. -
#database_path ⇒ String
The SQLite file,
"storage/<env>.sqlite3", fromCYBERTRAIN_DATABASE. -
#env ⇒ String
The environment:
"development"(the default),"test"or"production"(the default in a binary fromcybertrain build). -
#host ⇒ String
The address the server binds,
"127.0.0.1", fromCYBERTRAIN_HOST. -
#layout ⇒ String
The layout every template renders in,
"layouts/application"(app/views/layouts/application.html.erb); ignored when that file does not exist. -
#log_level ⇒ Symbol
:info(the default),:debug,:warn,:error, or:none, which also turns off the request log but still prints errors. -
#max_render_depth ⇒ Integer
How many renders may be open at once (the page and its nested partials),
12. -
#pool_size ⇒ Integer
SQLite connections in the pool,
4. -
#port ⇒ Integer
The port,
3000, fromPORT. -
#public_root ⇒ String
The static files directory,
"public", served before routing, and wherepublic/<status>.htmlerror pages are found in production. -
#secret_key_base ⇒ String
The secret the session cookie is signed with, from
CYBERTRAIN_SECRET_KEY_BASE. -
#secret_key_path ⇒ String
Where development and test keep their generated secret,
"tmp/secret_key". -
#session_cookie_name ⇒ String
The session cookie’s name,
"_cybertrain_session". -
#session_max_age ⇒ Integer
The session cookie’s Max-Age in seconds, two weeks (
1209600). -
#session_partitioned ⇒ Boolean
Whether the session cookie is
Partitioned,false, fromCYBERTRAIN_SESSION_PARTITIONED(1ortrue); it addsSecuretoo. -
#session_same_site ⇒ String
The session cookie’s SameSite attribute,
"Lax", fromCYBERTRAIN_SESSION_SAME_SITE:"Lax","Strict"or"None"; any other value stops the server at boot. -
#session_secure ⇒ Boolean
Whether the session cookie is
Secure(HTTPS only): true in production, false elsewhere. -
#static_files ⇒ Boolean
Whether
public/is served,true. -
#views_root ⇒ String
Where templates are read from in development and test,
"app/views". -
#workers ⇒ Integer
Spinel worker threads,
1, fromSPINEL_WORKERS.
Instance Method Summary collapse
Instance Attribute Details
#csrf ⇒ Boolean
Whether non-GET requests must carry the CSRF token, true. A request
without it gets 403.
134 135 136 |
# File 'cybertrain/config.rb', line 134 def csrf @csrf end |
#database_path ⇒ String
The SQLite file, "storage/<env>.sqlite3", from CYBERTRAIN_DATABASE.
Relative to the working directory.
51 52 53 |
# File 'cybertrain/config.rb', line 51 def database_path @database_path end |
#env ⇒ String
The environment: "development" (the default), "test" or
"production" (the default in a binary from cybertrain build). From
CYBERTRAIN_ENV. Set the variable rather than this attribute:
database_path and session_secure are derived from it before
config/app.rb runs.
32 33 34 |
# File 'cybertrain/config.rb', line 32 def env @env end |
#host ⇒ String
The address the server binds, "127.0.0.1", from CYBERTRAIN_HOST. Use
"0.0.0.0" to listen on every interface (in a container; behind a
reverse proxy, keep the default).
39 40 41 |
# File 'cybertrain/config.rb', line 39 def host @host end |
#layout ⇒ String
The layout every template renders in, "layouts/application"
(app/views/layouts/application.html.erb); ignored when that file does
not exist.
78 79 80 |
# File 'cybertrain/config.rb', line 78 def layout @layout end |
#log_level ⇒ Symbol
:info (the default), :debug, :warn, :error, or :none, which
also turns off the request log but still prints errors. Lines go to
standard output as [INFO] ....
85 86 87 |
# File 'cybertrain/config.rb', line 85 def log_level @log_level end |
#max_render_depth ⇒ Integer
How many renders may be open at once (the page and its nested partials),
12. Raise it for partials that recurse deeper, such as threaded
comments; it must be at least 1.
152 153 154 |
# File 'cybertrain/config.rb', line 152 def max_render_depth @max_render_depth end |
#pool_size ⇒ Integer
SQLite connections in the pool, 4.
122 123 124 |
# File 'cybertrain/config.rb', line 122 def pool_size @pool_size end |
#port ⇒ Integer
The port, 3000, from PORT. A port given on the command line (./blog
8080, cybertrain server 8080) wins.
45 46 47 |
# File 'cybertrain/config.rb', line 45 def port @port end |
#public_root ⇒ String
The static files directory, "public", served before routing, and where
public/<status>.html error pages are found in production.
71 72 73 |
# File 'cybertrain/config.rb', line 71 def public_root @public_root end |
#secret_key_base ⇒ String
The secret the session cookie is signed with, from
CYBERTRAIN_SECRET_KEY_BASE. Required in production (boot fails without
it; openssl rand -hex 32 makes one); development and test create one
in tmp/secret_key. Changing it ends every session.
59 60 61 |
# File 'cybertrain/config.rb', line 59 def secret_key_base @secret_key_base end |
#secret_key_path ⇒ String
Where development and test keep their generated secret,
"tmp/secret_key".
145 146 147 |
# File 'cybertrain/config.rb', line 145 def secret_key_path @secret_key_path end |
#session_cookie_name ⇒ String
The session cookie’s name, "_cybertrain_session".
90 91 92 |
# File 'cybertrain/config.rb', line 90 def @session_cookie_name end |
#session_max_age ⇒ Integer
The session cookie’s Max-Age in seconds, two weeks (1209600). It
restarts whenever the session changes.
96 97 98 |
# File 'cybertrain/config.rb', line 96 def session_max_age @session_max_age end |
#session_partitioned ⇒ Boolean
Whether the session cookie is Partitioned, false, from
CYBERTRAIN_SESSION_PARTITIONED (1 or true); it adds Secure too.
With "None" it is for an app shown inside another site’s frame,
such as an editor’s preview.
117 118 119 |
# File 'cybertrain/config.rb', line 117 def session_partitioned @session_partitioned end |
#session_same_site ⇒ String
The session cookie’s SameSite attribute, "Lax", from
CYBERTRAIN_SESSION_SAME_SITE: "Lax", "Strict" or "None"; any
other value stops the server at boot. "None" always adds Secure.
109 110 111 |
# File 'cybertrain/config.rb', line 109 def session_same_site @session_same_site end |
#session_secure ⇒ Boolean
Whether the session cookie is Secure (HTTPS only): true in production,
false elsewhere.
102 103 104 |
# File 'cybertrain/config.rb', line 102 def session_secure @session_secure end |
#static_files ⇒ Boolean
Whether public/ is served, true. Turn it off when the reverse proxy
serves it.
128 129 130 |
# File 'cybertrain/config.rb', line 128 def static_files @static_files end |
#views_root ⇒ String
Where templates are read from in development and test, "app/views". A
production binary uses the templates embedded by cybertrain build.
65 66 67 |
# File 'cybertrain/config.rb', line 65 def views_root @views_root end |
#workers ⇒ Integer
Spinel worker threads, 1, from SPINEL_WORKERS.
139 140 141 |
# File 'cybertrain/config.rb', line 139 def workers @workers end |
Instance Method Details
#development? ⇒ Boolean
229 230 231 |
# File 'cybertrain/config.rb', line 229 def development? @env == "development" end |
#production? ⇒ Boolean
241 242 243 |
# File 'cybertrain/config.rb', line 241 def production? @env == "production" end |
#test? ⇒ Boolean
235 236 237 |
# File 'cybertrain/config.rb', line 235 def test? @env == "test" end |