Class: Cybertrain::Config

Inherits:
Object
  • Object
show all
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.

Examples:

config/app.rb

Cybertrain.configure do |c|
  c.log_level = :none if c.test?
  c.max_render_depth = 20
end
Cybertrain.url_root = "https://example.com" if Cybertrain.config.production?

Instance Attribute Summary collapse

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.

Returns:

  • (Boolean)


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.

Returns:

  • (String)


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.

Returns:

  • (String)


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).

Returns:

  • (String)


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.

Returns:

  • (String)


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] ....

Returns:

  • (Symbol)


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.

Returns:

  • (Integer)


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.

Returns:

  • (Integer)


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.

Returns:

  • (Integer)


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.

Returns:

  • (String)


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.

Returns:

  • (String)


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".

Returns:

  • (String)


145
146
147
# File 'cybertrain/config.rb', line 145

def secret_key_path
  @secret_key_path
end

The session cookie’s name, "_cybertrain_session".

Returns:

  • (String)


90
91
92
# File 'cybertrain/config.rb', line 90

def session_cookie_name
  @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.

Returns:

  • (Integer)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (String)


65
66
67
# File 'cybertrain/config.rb', line 65

def views_root
  @views_root
end

#workers ⇒ Integer

Spinel worker threads, 1, from SPINEL_WORKERS.

Returns:

  • (Integer)


139
140
141
# File 'cybertrain/config.rb', line 139

def workers
  @workers
end

Instance Method Details

#development? ⇒ Boolean

Returns:

  • (Boolean)


229
230
231
# File 'cybertrain/config.rb', line 229

def development?
  @env == "development"
end

#production? ⇒ Boolean

Returns:

  • (Boolean)


241
242
243
# File 'cybertrain/config.rb', line 241

def production?
  @env == "production"
end

#test? ⇒ Boolean

Returns:

  • (Boolean)


235
236
237
# File 'cybertrain/config.rb', line 235

def test?
  @env == "test"
end