Class: Cybertrain::Config

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/config.rb,
cybertrain/encryptor.rb,
cybertrain/config/validation.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_ALLOWED_HOSTS, CYBERTRAIN_SESSION_SAME_SITE, CYBERTRAIN_SESSION_PARTITIONED, CYBERTRAIN_MAX_PAGE, CYBERTRAIN_HTTP_ALLOW_PRIVATE, CYBERTRAIN_WORKER, CYBERTRAIN_I18N_DEFAULT_LOCALE, CYBERTRAIN_AUTH_LOCKOUT_ATTEMPTS, CYBERTRAIN_AUTH_LOCKOUT_PERIOD, CYBERTRAIN_AUTH_REMEMBER_FOR, CYBERTRAIN_AUTH_IDLE_TIMEOUT); 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

#allowed_hosts ⇒ Array<String>

Hostnames development requests may use, even when listening on “0.0.0.0”. Defaults to localhost, 127.0.0.1 and [::1]; the comma-separated CYBERTRAIN_ALLOWED_HOSTS adds exact forwarding hostnames. No wildcards, schemes or ports; IPv6 addresses include brackets. An empty list denies every host. CYBERTRAIN_HOSTS entries (#hosts_from_env) are appended too, and turn the same check on in production and test (#host_check?); without them those environments do not check.

Returns:

  • (Array<String>)


60
61
62
# File 'cybertrain/config.rb', line 60

def allowed_hosts
  @allowed_hosts
end

#auth_idle_timeout ⇒ Integer

Seconds without a request after which a session ends, 604800 (7 days), from CYBERTRAIN_AUTH_IDLE_TIMEOUT. 0 turns it off.

Returns:



1036
1037
1038
# File 'cybertrain/config.rb', line 1036

def auth_idle_timeout
  @auth_idle_timeout
end

#auth_lockout_attempts ⇒ Integer

Failed sign-ins before an account is locked, 10, from CYBERTRAIN_AUTH_LOCKOUT_ATTEMPTS. 0 turns lockout off.

Returns:



1018
1019
1020
# File 'cybertrain/config.rb', line 1018

def auth_lockout_attempts
  @auth_lockout_attempts
end

#auth_lockout_period ⇒ Integer

How long a lockout lasts, in seconds, 3600, from CYBERTRAIN_AUTH_LOCKOUT_PERIOD. At least 1.

Returns:



1024
1025
1026
# File 'cybertrain/config.rb', line 1024

def auth_lockout_period
  @auth_lockout_period
end

#auth_remember_for ⇒ Integer

How long a “remember me” sign-in lasts, in seconds, 2592000 (30 days), from CYBERTRAIN_AUTH_REMEMBER_FOR. At least 1.

Returns:



1030
1031
1032
# File 'cybertrain/config.rb', line 1030

def auth_remember_for
  @auth_remember_for
end

#cache_prune_interval ⇒ Integer

Seconds between two prunes of expired Cybertrain::Cache rows, 300, from CYBERTRAIN_CACHE_PRUNE_INTERVAL. With cybertrain/jobs it is the interval of the scheduled task "cybertrain cache prune", read once, when the task is registered (requiring cybertrain/cache and cybertrain/jobs); without jobs a cache write prunes when this long has passed since the last prune (Cybertrain::Cache.prune_if_due), reading it each time. At least 1.

Returns:



871
872
873
# File 'cybertrain/config.rb', line 871

def cache_prune_interval
  @cache_prune_interval
end

#content_security_policy_nonce_directives ⇒ Array<String>

The directives that get this request’s nonce ('nonce-...'), []: with %w[script-src style-src], a <script> written with javascript_tag(nonce: true) runs under script-src 'self'. A name that is not a directive stops the server at boot.

Returns:

  • (Array<String>)


378
379
380
# File 'cybertrain/config.rb', line 378

def content_security_policy_nonce_directives
  @content_security_policy_nonce_directives
end

#content_security_policy_report_only ⇒ Boolean

Whether the Content Security Policy is sent as Content-Security-Policy-Report-Only (the browser reports violations and blocks nothing), false.

Returns:

  • (Boolean)


370
371
372
# File 'cybertrain/config.rb', line 370

def content_security_policy_report_only
  @content_security_policy_report_only
end

#csrf ⇒ Boolean

Whether non-GET requests must carry the CSRF token, true. A request without it gets 403. cybertrain test turns it off for its tests unless config/app.rb assigns it (Rails’ test environment has forgery protection off).

Returns:

  • (Boolean)


397
398
399
# File 'cybertrain/config.rb', line 397

def csrf
  @csrf
end

#csrf_exempt_prefixes ⇒ Array<String>

Path prefixes whose non-GET requests skip the CSRF check, []: for an API that other programs call with a token of its own (a webhook receiver, an SDK’s ingest endpoint), where no browser session exists. A prefix is compared with the request path as sent (not decoded) from its first byte, so give it with both slashes: "/api/" exempts /api/notes and /api/1/events/, not /apix. Anything not under a listed prefix is checked as before. The exempt controller must authenticate its callers itself (an API key in a header).

Examples:

config/app.rb

c.csrf_exempt_prefixes = ["/api/"]

Returns:

  • (Array<String>)


447
448
449
# File 'cybertrain/config.rb', line 447

def csrf_exempt_prefixes
  @csrf_exempt_prefixes
end

#database_path ⇒ String

The SQLite file, "storage/<env>.sqlite3", from CYBERTRAIN_DATABASE. Relative to the working directory.

Returns:

  • (String)


72
73
74
# File 'cybertrain/config.rb', line 72

def database_path
  @database_path
end

#encryption_key ⇒ String

The key encrypted columns (encrypts :api_key in a model) are encrypted with: 64 hex characters (32 bytes) from CYBERTRAIN_ENCRYPTION_KEY, “” when unset. cybertrain secret --hex makes one. It is not derived from #secret_key_base, so rotating the session secret leaves stored data readable. Boot fails on a malformed key, and on an empty one when a model declares encrypts (#encryption_error).

Returns:

  • (String)


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

def encryption_key
  @encryption_key
end

#encryption_keys_previous ⇒ Array<String>

Earlier encryption keys, tried in order after #encryption_key when a stored value does not decrypt with it, and never used to encrypt: CYBERTRAIN_ENCRYPTION_KEY_PREVIOUS, a comma-separated list of 64-hex keys. To rotate, make a new key, move the old one here, and re-save the records (each save encrypts with the current key).

Returns:

  • (Array<String>)


100
101
102
# File 'cybertrain/config.rb', line 100

def encryption_keys_previous
  @encryption_keys_previous
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)


42
43
44
# File 'cybertrain/config.rb', line 42

def env
  @env
end

#error_sample_rate ⇒ Float

The share of error reports the Sentry sender sends, as Sentry’s sample_rate, 1.0 (all), from CYBERTRAIN_ERROR_SAMPLE_RATE (digits with an optional fraction: 0.25); subscribers see every report. Outside 0.0 to 1.0, or a variable that is not such a number, stops the boot (#reporting_error).

Returns:

  • (Float)


678
679
680
# File 'cybertrain/config.rb', line 678

def error_sample_rate
  @error_sample_rate
end

#feed_restart_limit ⇒ Integer

How many times the supervisor may restart one feed’s thread within #feed_restart_window: a feed that dies again after that many restarts makes a feeds process exit with status 1 (at FATAL, feed NAME restarted N times in W s; exiting), 10, from CYBERTRAIN_FEED_RESTART_LIMIT. A server process that runs feeds keeps restarting them. At least 1.

Returns:



889
890
891
# File 'cybertrain/config.rb', line 889

def feed_restart_limit
  @feed_restart_limit
end

#feed_restart_window ⇒ Integer

The window #feed_restart_limit counts in, in seconds, 600, from CYBERTRAIN_FEED_RESTART_WINDOW. At least 1.

Returns:



895
896
897
# File 'cybertrain/config.rb', line 895

def feed_restart_window
  @feed_restart_window
end

#feed_status_interval ⇒ Integer

Seconds between the writes of the feeds’ status rows (cybertrain_feeds, WebSocket.publish_status) by the supervisor of a process that runs feeds, 10, from CYBERTRAIN_FEED_STATUS_INTERVAL. At least 1.

Returns:



879
880
881
# File 'cybertrain/config.rb', line 879

def feed_status_interval
  @feed_status_interval
end

#filter_parameters ⇒ Array<String>

The parameter names whose values are replaced with [FILTERED] in the request log’s Started line and on the development error page (Rails’ filter_parameters): password, password_confirmation, token, secret, secret_key_base, session_key, api_key and authorization, or the comma-separated names in CYBERTRAIN_FILTER_PARAMETERS instead. A parameter is filtered when its name contains one of them, ASCII case-insensitively (password filters user[password]). [] turns filtering off.

Examples:

config/app.rb

config.filter_parameters = config.filter_parameters + ["otp", "ssn"]

Returns:

  • (Array<String>)


1438
1439
1440
# File 'cybertrain/config.rb', line 1438

def filter_parameters
  @filter_parameters
end

#force_ssl ⇒ Boolean

Whether http requests are redirected to https and https responses carry Strict-Transport-Security: max-age=63072000; includeSubDomains (SslRedirect), false, from CYBERTRAIN_FORCE_SSL (1 or true; 0, false or empty is off, anything else stops the server at boot). Behind a TLS-terminating proxy the request counts as https when it says X-Forwarded-Proto: https (the first element of a list). Request#base_url believes that header only from a trusted proxy, so also set #trusted_proxy or #trusted_proxies, or URLs the app builds (a turbo_stream_from ws: true URL) say http and ws. The health path is never redirected. On, the session and cookie jar cookies are Secure whatever #session_secure says (#secure_cookies?). cybertrain test turns it off for its tests unless config/app.rb assigns it (an exported CYBERTRAIN_FORCE_SSL would answer every test request with a redirect to https).

Returns:

  • (Boolean)


298
299
300
# File 'cybertrain/config.rb', line 298

def force_ssl
  @force_ssl
end

#health_feed_stale ⇒ Integer

Seconds after which a feed row’s updated_at (the publishing process) or COALESCE(last_activity_at, started_at) (the feed) makes the health check answer 503 feed stale, 180, from CYBERTRAIN_HEALTH_FEED_STALE (a bad value is the default, one below 1 is refused at boot). At least 1, and while #health_feeds is on more than #feed_status_interval (boot refuses it otherwise: every row would be stale between two writes). A row whose feed no registered subscription names is not counted.

Returns:



944
945
946
# File 'cybertrain/config.rb', line 944

def health_feed_stale
  @health_feed_stale
end

#health_feeds ⇒ Boolean

Whether the health check also reads the feed status rows (WebSocket::FeedTable) and answers 503 feed stale when a feed’s publisher or the feed itself has been silent for #health_feed_stale seconds. true; CYBERTRAIN_HEALTH_FEEDS=0 (or false) turns it off, for a server whose feeds run in another process that is watched on its own.

Returns:

  • (Boolean)


932
933
934
# File 'cybertrain/config.rb', line 932

def health_feeds
  @health_feeds
end

#health_path ⇒ String

The path of the built-in health check, "/up", from CYBERTRAIN_HEALTH_PATH (set to an empty value, or c.health_path = "", to turn it off; unset is the default). A GET or HEAD of exactly this path is answered before the static files, the session, CSRF and the router (so no controller and no login before_action sees it): 200 ok when a query reading the database’s schema succeeds, 503 database unavailable when it fails, and 503 worker stale when the Scheduler runs and has not ticked for #health_worker_stale seconds; text/plain, Cache-Control: no-store, no cookie. Must start with “/” (boot refuses anything else).

Returns:

  • (String)


915
916
917
# File 'cybertrain/config.rb', line 915

def health_path
  @health_path
end

#health_worker_stale ⇒ Integer

Seconds after the Scheduler’s last tick at which the health check answers 503 worker stale, 300: a task that runs longer (or a stuck one) shows up there. Only while the scheduler runs. At least 1.

Returns:



922
923
924
# File 'cybertrain/config.rb', line 922

def health_worker_stale
  @health_worker_stale
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)


49
50
51
# File 'cybertrain/config.rb', line 49

def host
  @host
end

#hosts_from_env ⇒ Array<String>

The Host names from CYBERTRAIN_HOSTS (comma-separated, [] when unset), also appended to #allowed_hosts, after its loopback names: with the check on, localhost, 127.0.0.1 and [::1] are accepted too (a browser sends those only to its own machine). Set, they turn the host check on outside development (#host_check?): a request whose Host is not in #allowed_hosts or this list answers 403. Exact names (an IPv6 address in brackets); no scheme, path, port or wildcard (boot refuses one). cybertrain test empties it for its tests unless config/app.rb assigns or changes it (an exported CYBERTRAIN_HOSTS would turn the host check on and answer the test host 403).

Returns:

  • (Array<String>)


335
336
337
# File 'cybertrain/config.rb', line 335

def hosts_from_env
  @hosts_from_env
end

#http_allow_private ⇒ Boolean

Whether HttpClient may connect to addresses that are not public (loopback, private, link-local, CGNAT, multicast, …; see Net::Address), false, from CYBERTRAIN_HTTP_ALLOW_PRIVATE (1 or true). Off, a URL whose host resolves to such an address raises HttpClient::BlockedAddressError before anything is sent, which keeps a user-supplied webhook URL from reaching the server’s own network. Turn it on for a test against a local server, or for an internal service the application is meant to call.

Returns:

  • (Boolean)


516
517
518
# File 'cybertrain/config.rb', line 516

def http_allow_private
  @http_allow_private
end

#i18n_available_locales ⇒ Array<Symbol>

The locales I18n.locale= and Request#preferred_locale accept. Empty (the default) means just #i18n_default_locale; read the effective list with #i18n_locales.

Examples:

config/app.rb

config.i18n_available_locales = [:en, :ja]

Returns:

  • (Array<Symbol>)


1006
1007
1008
# File 'cybertrain/config.rb', line 1006

def i18n_available_locales
  @i18n_available_locales
end

#i18n_default_locale ⇒ Symbol

The locale a request and a thread start in, :en, from CYBERTRAIN_I18N_DEFAULT_LOCALE (a name such as en or pt-BR). Boot refuses a name that is not one, or a default outside #i18n_available_locales when that is not empty.

Returns:

  • (Symbol)


997
998
999
# File 'cybertrain/config.rb', line 997

def i18n_default_locale
  @i18n_default_locale
end

#i18n_raise_on_missing ⇒ Boolean

Whether a missing translation raises I18n::MissingTranslationData instead of answering a marker or the humanised key, false.

Returns:

  • (Boolean)


1012
1013
1014
# File 'cybertrain/config.rb', line 1012

def i18n_raise_on_missing
  @i18n_raise_on_missing
end

#job_drain_timeout ⇒ Integer

Seconds Job.stop! waits at shutdown for the jobs that are running to finish, 10; the rows of jobs still running then are left to heartbeat recovery. At least 1.

Returns:



811
812
813
# File 'cybertrain/config.rb', line 811

def job_drain_timeout
  @job_drain_timeout
end

#job_heartbeat_interval ⇒ Integer

Seconds between the writes that mark this process’s running jobs as alive (heartbeat_at), 30. At least 1.

Returns:



797
798
799
# File 'cybertrain/config.rb', line 797

def job_heartbeat_interval
  @job_heartbeat_interval
end

#job_heartbeat_stale ⇒ Integer

Seconds without a heartbeat after which a running job counts as abandoned (its process died) and Job.recover! queues it again, 300. More than #job_heartbeat_interval.

Returns:



804
805
806
# File 'cybertrain/config.rb', line 804

def job_heartbeat_stale
  @job_heartbeat_stale
end

#job_max_attempts ⇒ Integer

How many attempts a Job gets before it is left failed, 5 (the first run and four retries, 1, 5, 15 and 60 minutes apart).

Returns:



901
902
903
# File 'cybertrain/config.rb', line 901

def job_max_attempts
  @job_max_attempts
end

#job_poll_interval ⇒ Integer

Seconds an idle job thread waits before it looks at cybertrain_jobs again, 1: a job enqueued to run now starts within about this long. At least 1.

Returns:



783
784
785
# File 'cybertrain/config.rb', line 783

def job_poll_interval
  @job_poll_interval
end

#job_threads ⇒ Integer

How many job threads a process that runs jobs starts, 3, from CYBERTRAIN_JOB_THREADS: that many jobs run at once in it (green threads; a SQLite call still holds an OS worker while it runs). At least 1.

Returns:



791
792
793
# File 'cybertrain/config.rb', line 791

def job_threads
  @job_threads
end

#jobs_page_per_page ⇒ Integer

How many rows each list of the jobs page (jobs_page in config/routes.rb, JobsPage) shows on one page, 50, from CYBERTRAIN_JOBS_PAGE_PER_PAGE; ?page=N reaches the others. At least 1.

Returns:



860
861
862
# File 'cybertrain/config.rb', line 860

def jobs_page_per_page
  @jobs_page_per_page
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)


119
120
121
# File 'cybertrain/config.rb', line 119

def layout
  @layout
end

#log_format ⇒ Symbol

How log lines are written: :text (the default, 2026-11-11T12:00:00.123Z INFO Completed 200 in 12ms) or :json, one JSON object per line for log collectors; from CYBERTRAIN_LOG_FORMAT. Anything else stops the boot (#log_error). cybertrain test keeps text lines for its tests unless config/app.rb assigns it (tests read captured log text); the variable does not count as an assignment there.

Returns:

  • (Symbol)


166
167
168
# File 'cybertrain/config.rb', line 166

def log_format
  @log_format
end

#log_level ⇒ Symbol

:info (the default), :debug, :warn, :error, :fatal, or :none, which also turns off the request log but still prints errors; from CYBERTRAIN_LOG_LEVEL (debug … none). Anything else stops the boot (#log_error). cybertrain test sets :none for its tests unless config/app.rb assigns it (the request log would print between the test lines); the variable does not count as an assignment there.

Returns:

  • (Symbol)


130
131
132
# File 'cybertrain/config.rb', line 130

def log_level
  @log_level
end

#log_tags ⇒ Array<Symbol>

The request’s tags on every log line it causes, in order, [:request_id]: :request_id (the request id) and :remote_ip (Request#client_ip; off by default, it is personal data). [] turns the request tag off. Anything else stops the boot (#log_error); Rails also takes Procs, which this does not.

Examples:

config/app.rb

c.log_tags = [:request_id, :remote_ip]

Returns:

  • (Array<Symbol>)


201
202
203
# File 'cybertrain/config.rb', line 201

def log_tags
  @log_tags
end

#mail_delivery_method ⇒ Symbol

How Mailer delivers, from CYBERTRAIN_MAIL_DELIVERY_METHOD (smtp or test, in any case): :smtp sends through the server above; :test (Rails’ delivery_method = :test) checks each message and appends it to Mailer.deliveries instead of connecting. The default is :test in the test environment (CYBERTRAIN_ENV=test, which cybertrain test sets) and :smtp in every other. A test that reads mail at a Test::SmtpReceiver sets :smtp first. Boot refuses anything else (#mail_delivery_error), and logs a warning for :test outside the test environment (#mail_delivery_warning): no mail is sent then. cybertrain test keeps its tests at :test whatever CYBERTRAIN_MAIL_DELIVERY_METHOD says, unless config/app.rb assigns it (an exported smtp must not make a test send real mail).

Examples:

a test of the SMTP path

Cybertrain.config.mail_delivery_method = :smtp

Returns:

  • (Symbol)


598
599
600
# File 'cybertrain/config.rb', line 598

def mail_delivery_method
  @mail_delivery_method
end

#max_body_bytes ⇒ Integer

The largest request body the server accepts, in bytes, 10485760 (10 MiB); a longer one is answered 413 before the body is read. Raise it for an endpoint that receives large uploads or compressed payloads (the limit is on the bytes on the wire; see Request#decoded_body for the decoded size).

Returns:



456
457
458
# File 'cybertrain/config.rb', line 456

def max_body_bytes
  @max_body_bytes
end

#max_multipart_parts ⇒ Integer

The most parts (text fields plus files) in one multipart body, 128 (1 to 4096); more is answered 400.

Returns:



471
472
473
# File 'cybertrain/config.rb', line 471

def max_multipart_parts
  @max_multipart_parts
end

#max_page ⇒ Integer

The largest page number Params#page_number gives and Relation#page accepts, 10000, from CYBERTRAIN_MAX_PAGE (an optional - and at most 18 digits; anything else, or a value below 1, is the default). It bounds the OFFSET a request can ask for, at (max_page - 1) * per rows. At least 1 (boot refuses less).

Returns:



750
751
752
# File 'cybertrain/config.rb', line 750

def max_page
  @max_page
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:



741
742
743
# File 'cybertrain/config.rb', line 741

def max_render_depth
  @max_render_depth
end

#max_upload_bytes ⇒ Integer

The largest single uploaded file in a multipart/form-data body, in bytes, 5242880 (5 MiB); a bigger file part is answered 400. Boot refuses a value over #max_body_bytes, which bounds the whole body (raise both for bigger files). The server buffers the whole body, so memory use is about three times the body per request in flight.

Returns:



465
466
467
# File 'cybertrain/config.rb', line 465

def max_upload_bytes
  @max_upload_bytes
end

#permissions_policy ⇒ String

The Permissions-Policy every response carries unless it sets its own, "camera=(), microphone=(), geolocation=()"; "" sends none. A CR or LF stops the server at boot.

Examples:

config/app.rb

c.permissions_policy = "camera=(), microphone=(), geolocation=(self)"

Returns:

  • (String)


363
364
365
# File 'cybertrain/config.rb', line 363

def permissions_policy
  @permissions_policy
end

#pool_size ⇒ Integer

SQLite connections in the pool, 4.

Returns:



383
384
385
# File 'cybertrain/config.rb', line 383

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:



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

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)


112
113
114
# File 'cybertrain/config.rb', line 112

def public_root
  @public_root
end

#release ⇒ String

The release sent with each error report (a version or a commit), "", from CYBERTRAIN_RELEASE.

Returns:

  • (String)


693
694
695
# File 'cybertrain/config.rb', line 693

def release
  @release
end

#reuse_port ⇒ Boolean

Whether the server binds with SO_REUSEPORT, false; true from CYBERTRAIN_REUSE_PORT=1 (or true). Several processes then listen on one port and, on Linux, the kernel splits connections between them (docs/deploy.md); macOS binds but does not distribute. A process left running keeps taking traffic without any bind error. Ignored, with a warning, in development.

Returns:

  • (Boolean)


770
771
772
# File 'cybertrain/config.rb', line 770

def reuse_port
  @reuse_port
end

#scheduler_interval ⇒ Integer

Seconds the scheduler thread sleeps between ticks, 1: a task runs at most this late. At least 1.

Returns:



776
777
778
# File 'cybertrain/config.rb', line 776

def scheduler_interval
  @scheduler_interval
end

#scheduler_lease_ttl ⇒ Integer

Seconds the scheduler’s lease lasts unless renewed, 30: of several processes sharing a database, the one holding the lease runs the scheduled tasks, and another takes over at most this long after it stops ticking. At least 1.

Returns:



819
820
821
# File 'cybertrain/config.rb', line 819

def scheduler_lease_ttl
  @scheduler_lease_ttl
end

#scheduler_tz ⇒ String

The zone a Scheduler.cron task’s expression is read in when it names none (tz:), from CYBERTRAIN_SCHEDULER_TZ: an IANA name such as "Asia/Tokyo" (TimeZone.find). While neither the variable nor an assignment set it, it is #time_zone (read each time, so a later c.time_zone = moves it too). Boot refuses a name the system zoneinfo does not have.

Returns:

  • (String)


843
844
845
846
# File 'cybertrain/config.rb', line 843

def scheduler_tz
  own = @scheduler_tz
  own.empty? ? @time_zone : own
end

#secret_key_base ⇒ String

The secret the session and cookie keys are derived from, 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)


80
81
82
# File 'cybertrain/config.rb', line 80

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)


734
735
736
# File 'cybertrain/config.rb', line 734

def secret_key_path
  @secret_key_path
end

#sentry_dsn ⇒ String

The Sentry (or GlitchTip) DSN error reports are sent to, from CYBERTRAIN_SENTRY_DSN, "" (nothing is sent): https://<public key>@<host>[:<port>][/<path>]/<project id> (SentryDsn). One that does not parse stops the boot (#reporting_error), which names the reason and never the key. cybertrain test empties it for its tests unless config/app.rb assigns it (an exported DSN must not make a test send reports); a test points it at a receiver by assignment.

Returns:

  • (String)


645
646
647
# File 'cybertrain/config.rb', line 645

def sentry_dsn
  @sentry_dsn
end

#session_absolute_max_age ⇒ Integer

The longest a session lives in seconds, however often it is used, two weeks (1209600); 0 turns the limit off. The session cookie records when it was first written, signed with the rest, and a cookie older than this loads as an empty session, so a copied cookie cannot be replayed past it. Session#restart_lifetime! starts the count again (generated authentication calls it at sign-in, and also ends a sign-in this long after its Session row’s created_at).

Returns:



224
225
226
# File 'cybertrain/config.rb', line 224

def session_absolute_max_age
  @session_absolute_max_age
end

The session cookie’s name, "_cybertrain_session".

Returns:

  • (String)


206
207
208
# File 'cybertrain/config.rb', line 206

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; #session_absolute_max_age bounds the session’s whole life.

Returns:



213
214
215
# File 'cybertrain/config.rb', line 213

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)


245
246
247
# File 'cybertrain/config.rb', line 245

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)


237
238
239
# File 'cybertrain/config.rb', line 237

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)


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

def session_secure
  @session_secure
end

#smtp_from ⇒ String

The default sender address, "", from CYBERTRAIN_SMTP_FROM. cybertrain test gives its tests "from@example.com" (Rails’ convention) unless the variable or config/app.rb set one.

Returns:

  • (String)


551
552
553
# File 'cybertrain/config.rb', line 551

def smtp_from
  @smtp_from
end

#smtp_host ⇒ String

The SMTP server Mailer sends through, "" (unset: Mailer.new raises until it is set), from CYBERTRAIN_SMTP_HOST.

Returns:

  • (String)


524
525
526
# File 'cybertrain/config.rb', line 524

def smtp_host
  @smtp_host
end

#smtp_password ⇒ String

The AUTH PLAIN password, "", from CYBERTRAIN_SMTP_PASSWORD. A secret: the boot banner, help, logs and Mailer’s error messages never show it.

Returns:

  • (String)


544
545
546
# File 'cybertrain/config.rb', line 544

def smtp_password
  @smtp_password
end

#smtp_port ⇒ Integer

Its port, 0, from CYBERTRAIN_SMTP_PORT: 0 means the mode’s port, 587 for "starttls", 465 for "tls", 25 for "none" (Mailer.default_port). A value that is not a number from 1 to 65535 is 0.

Returns:



532
533
534
# File 'cybertrain/config.rb', line 532

def smtp_port
  @smtp_port
end

#smtp_tls ⇒ String

How the connection is protected, "starttls", from CYBERTRAIN_SMTP_TLS: "starttls" (upgrade a plain connection, port 587), "tls" (TLS from the first byte, port 465) or "none" (plain text, which sends credentials only to a loopback address). Both TLS modes need require "cybertrain/net/tls".

Returns:

  • (String)


579
580
581
# File 'cybertrain/config.rb', line 579

def smtp_tls
  @smtp_tls
end

#smtp_user ⇒ String

The AUTH PLAIN user, "" (no AUTH), from CYBERTRAIN_SMTP_USER.

Returns:

  • (String)


537
538
539
# File 'cybertrain/config.rb', line 537

def smtp_user
  @smtp_user
end

#static_files ⇒ Boolean

Whether public/ is served, true. Turn it off when the reverse proxy serves it.

Returns:

  • (Boolean)


389
390
391
# File 'cybertrain/config.rb', line 389

def static_files
  @static_files
end

#stream_max_backlog ⇒ Integer

The most undelivered messages one connection may have waiting, 1000; past it the connection is closed and the client reconnects.

Returns:



989
990
991
# File 'cybertrain/config.rb', line 989

def stream_max_backlog
  @stream_max_backlog
end

#stream_max_connections ⇒ Integer

The most stream connections one process serves at once, 1000; past it the endpoint answers 503 (SSE) or closes with 1013 (WebSocket).

Returns:



977
978
979
# File 'cybertrain/config.rb', line 977

def stream_max_connections
  @stream_max_connections
end

#stream_max_message ⇒ Integer

The largest WebSocket message the endpoint accepts from a client, in bytes, 65536; a larger one closes the connection with 1009.

Returns:



983
984
985
# File 'cybertrain/config.rb', line 983

def stream_max_message
  @stream_max_message
end

#stream_path ⇒ String

The path of the realtime endpoint (Stream::Endpoint: Server-Sent Events and WebSocket), "/cybertrain/stream", from CYBERTRAIN_STREAM_PATH (an empty value, or c.stream_path = "", turns the endpoint off). Must start with “/”.

Returns:

  • (String)


952
953
954
# File 'cybertrain/config.rb', line 952

def stream_path
  @stream_path
end

#stream_ping_interval ⇒ Integer

Seconds of silence after which the endpoint sends a keep-alive (an SSE : ping comment, a WebSocket ping), 15. At least 1.

Returns:



971
972
973
# File 'cybertrain/config.rb', line 971

def stream_ping_interval
  @stream_ping_interval
end

#stream_poll_ms ⇒ Integer

Milliseconds between the stream poller’s looks at cybertrain_messages, 100: a broadcast reaches the browsers within about this long. At least 10.

Returns:



959
960
961
# File 'cybertrain/config.rb', line 959

def stream_poll_ms
  @stream_poll_ms
end

#stream_retention ⇒ Integer

Seconds a broadcast stays in cybertrain_messages, 60: what a reconnecting client can still ask for (Last-Event-ID). At least 1.

Returns:



965
966
967
# File 'cybertrain/config.rb', line 965

def stream_retention
  @stream_retention
end

#time_zone ⇒ String

The application’s time zone, "UTC", from CYBERTRAIN_TIME_ZONE: an IANA name such as "Asia/Tokyo" (TimeZone.find; Rails’ config.time_zone takes Rails’ own names, here IANA names only). Boot refuses a name the system zoneinfo does not have (#time_zone_error) and installs the zone as Time.zone (Cybertrain::Clock.zone): the boundaries of beginning_of_day and the other calendar methods, Date.current, l and time_tag follow it, and #scheduler_tz defaults to it. Values stay UTC instants.

Examples:

config/app.rb

c.time_zone = "Asia/Tokyo"

Returns:

  • (String)


833
834
835
# File 'cybertrain/config.rb', line 833

def time_zone
  @time_zone
end

#trusted_proxies ⇒ Array<String>

The proxies that may name the client besides loopback, [], from CYBERTRAIN_TRUSTED_PROXIES: comma-separated IPv4 or IPv6 addresses or CIDRs (172.16.0.0/12,10.0.0.0/8, or one 172.18.0.2). A request whose connection comes from inside one of them takes its Request#client_ip from the last hop of X-Forwarded-For. For a proxy that reaches the app over a network rather than loopback: kamal-proxy, which runs in its own Docker container and connects from the bridge network’s address (Docker hands those out of 172.16.0.0/12 by default). List only addresses no client can connect from: anyone inside a listed network can choose the address a rate limit counts. trusted_proxy is the shorthand for 127.0.0.0/8,::1; the two add up. An entry that is not an address or CIDR (or a prefix past /32 or /128) stops the server at boot.

Returns:

  • (Array<String>)


279
280
281
# File 'cybertrain/config.rb', line 279

def trusted_proxies
  @trusted_proxies
end

#trusted_proxy ⇒ Boolean

Whether a reverse proxy on this host may name the client, false, from CYBERTRAIN_TRUSTED_PROXY (1 or true). When true, a request whose connection comes from loopback (127.0.0.0/8, ::1) takes its Request#client_ip from the last hop of X-Forwarded-For, the one the proxy appended; any other connection keeps its peer address. Turn it on when the server listens on 127.0.0.1 behind nginx, Caddy or kamal-proxy on the same machine, so that Cybertrain::Controller.rate_limit counts each visitor rather than the proxy. Nothing changes for a client that connects directly from another machine: its header is ignored. The shorthand for trusted_proxies of 127.0.0.0/8,::1 (the IPv4-mapped ::ffff:127.x.x.x included); see #trusted_proxies for a proxy in another container or on another machine.

Returns:

  • (Boolean)


262
263
264
# File 'cybertrain/config.rb', line 262

def trusted_proxy
  @trusted_proxy
end

#upload_root ⇒ String

The directory BlobStore keeps uploaded files in, "storage/uploads" (relative to the working directory). It is created on the first write, not at boot, and is never under public/: storage/ is the persistent volume of a deployment, public/ is replaced on every build. cybertrain test gives its tests tmp/test_uploads, emptied when the tests start, unless config/app.rb assigns it.

Returns:

  • (String)


481
482
483
# File 'cybertrain/config.rb', line 481

def upload_root
  @upload_root
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)


106
107
108
# File 'cybertrain/config.rb', line 106

def views_root
  @views_root
end

#worker ⇒ Boolean

Whether a server process also runs the background work (the Scheduler’s tasks, the Job threads, the Background services such as WebSocket subscriptions), true; false from CYBERTRAIN_WORKER=0 (or false), when ./<app> worker and ./<app> feeds processes do that work instead. Those two roles set it to true themselves: running it is what they are for.

Returns:

  • (Boolean)


760
761
762
# File 'cybertrain/config.rb', line 760

def worker
  @worker
end

#workers ⇒ Integer

Spinel worker threads that serve requests, 1, from SPINEL_WORKERS: the core count on a server with more than one. Above 1 the server hands Spinel one more, since Spinel counts the main thread, which only waits (Application.spinel_workers). Development always serves on one and ignores this (Application.serving_workers).

Returns:



728
729
730
# File 'cybertrain/config.rb', line 728

def workers
  @workers
end

Instance Method Details

#bool_setting(name) ⇒ Boolean

The value of the boolean setting name (#setting_bool).

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

Raises:

  • (ArgumentError) —

    when no boolean setting of that name is declared



1688
1689
1690
1691
1692
1693
# File 'cybertrain/config.rb', line 1688

def bool_setting(name)
  key = name.to_s
  raise ArgumentError, "no boolean setting #{key} (declare it with setting_bool)" unless @setting_bools.key?(key)

  @setting_bools[key] == true
end

#checked_hosts ⇒ Array<String>

The Host names HostAuthorization accepts: #allowed_hosts and any #hosts_from_env entry not already among them (config/app.rb may assign either).

Returns:

  • (Array<String>)


1505
1506
1507
1508
1509
1510
# File 'cybertrain/config.rb', line 1505

def checked_hosts
  names = Array.new(0) { "" }
  @allowed_hosts.each { |h| names << h }
  @hosts_from_env.each { |h| names << h unless names.include?(h) }
  names
end

#content_security_policy {|policy| ... } ⇒ nil

Declares the application’s Content Security Policy (spec section 5, C-5): yields it to the block, made on the first call. Off by default; Cybertrain::ContentSecurityPolicyHeader writes it on every response, and a controller adjusts its own copy with Cybertrain::Controller.content_security_policy.

Examples:

config/app.rb

c.content_security_policy do |p|
  p.default_src :self
  p.script_src :self, "https://cdn.jsdelivr.net"
  p.style_src :self
end
c.content_security_policy_nonce_directives = %w[script-src style-src]

Yield Parameters:

Returns:

  • (nil)


1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'cybertrain/config.rb', line 1474

def content_security_policy(&block)
  policy = @content_security_policy
  if policy.nil?
    policy = ContentSecurityPolicy.new
    @content_security_policy = policy
  end
  block.call(policy)
  nil
end

#content_security_policy_value ⇒ ContentSecurityPolicy?

The policy #content_security_policy declared, nil when none was.

Returns:



1487
1488
1489
# File 'cybertrain/config.rb', line 1487

def content_security_policy_value
  @content_security_policy
end

#development? ⇒ Boolean

Returns:

  • (Boolean)


1562
1563
1564
# File 'cybertrain/config.rb', line 1562

def development?
  @env == "development"
end

#encryptor ⇒ Encryptor

The Encryptor for #encryption_key and #encryption_keys_previous, built on first use and again only when they change.

Returns:

Raises:

  • (Encryptor::Error) —

    when the key is unset or not 64 hex characters (boot reports this first: #encryption_error)



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

def encryptor
  Encryptor.for_keys(@encryption_key, @encryption_keys_previous)
end

#host_check? ⇒ Boolean

Whether HostAuthorization checks the Host header: always in development, elsewhere only when CYBERTRAIN_HOSTS named hosts (spec C-11; empty means no check, as Rails’ production default).

Returns:

  • (Boolean)


1496
1497
1498
# File 'cybertrain/config.rb', line 1496

def host_check?
  development? || !@hosts_from_env.empty?
end

#i18n_locales ⇒ Array<Symbol>

The locales in effect: #i18n_available_locales, or just #i18n_default_locale when that is empty.

Returns:

  • (Array<Symbol>)


1042
1043
1044
1045
1046
1047
# File 'cybertrain/config.rb', line 1042

def i18n_locales
  list = @i18n_available_locales
  return [@i18n_default_locale] if list.empty?

  list
end

#int_setting(name) ⇒ Integer

The value of the Integer setting name (#setting_int).

Parameters:

  • name (Symbol)

Returns:

Raises:

  • (ArgumentError) —

    when no Integer setting of that name is declared



1676
1677
1678
1679
1680
1681
# File 'cybertrain/config.rb', line 1676

def int_setting(name)
  key = name.to_s
  raise ArgumentError, "no integer setting #{key} (declare it with setting_int)" unless @setting_ints.key?(key)

  @setting_ints[key].to_i
end

#log_error ⇒ String

The error Application#boot reports for an unknown log_level (CYBERTRAIN_LOG_LEVEL), log_format (CYBERTRAIN_LOG_FORMAT) or entry of log_tags; “” when all are fine.

Returns:

  • (String)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'cybertrain/config/validation.rb', line 86

def log_error
  level = @log_level
  unless level == :debug || level == :info || level == :warn || level == :error || level == :fatal || level == :none
    return "log_level must be :debug, :info, :warn, :error, :fatal or :none (got #{level.inspect})"
  end

  format = @log_format
  return "log_format must be :text or :json (got #{format.inspect})" unless format == :text || format == :json

  tags = @log_tags
  i = 0
  while i < tags.size
    tag = tags[i]
    return "log_tags may hold :request_id and :remote_ip (got #{tag.inspect})" unless tag == :request_id || tag == :remote_ip

    i += 1
  end
  ""
end

#mail_delivery_error ⇒ String

The error Application#boot reports when mail_delivery_method is neither :smtp nor :test (from CYBERTRAIN_MAIL_DELIVERY_METHOD or an assignment); “” when it is one of them.

Returns:

  • (String)


264
265
266
267
268
269
# File 'cybertrain/config/validation.rb', line 264

def mail_delivery_error
  delivery = @mail_delivery_method
  return "" if delivery == :smtp || delivery == :test

  "mail_delivery_method must be :smtp or :test (got #{delivery.inspect})"
end

#mail_delivery_warning ⇒ String

The warning Application#boot logs (and boots on) when mail_delivery_method is :test outside the test environment: every mail is kept in memory and none is sent. “” otherwise.

Returns:

  • (String)


276
277
278
279
280
281
# File 'cybertrain/config/validation.rb', line 276

def mail_delivery_warning
  return "" unless @mail_delivery_method == :test && @env != "test"

  "mail_delivery_method is :test outside the test environment (env #{@env}): " \
    "mail is stored in memory (the mailer's deliveries) and not sent"
end

#production? ⇒ Boolean

Returns:

  • (Boolean)


1574
1575
1576
# File 'cybertrain/config.rb', line 1574

def production?
  @env == "production"
end

#reporting_error ⇒ String

The error Application#boot reports when sentry_dsn (CYBERTRAIN_SENTRY_DSN) is set and does not parse (SentryDsn.problem: the reason, never the key), or error_sample_rate (CYBERTRAIN_ERROR_SAMPLE_RATE) is not a number from 0.0 to 1.0; “” when both are fine. A refused variable is echoed by its first 20 bytes at most, followed by ... when it is longer: a DSN pasted into the wrong variable is not printed whole.

Returns:

  • (String)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'cybertrain/config/validation.rb', line 115

def reporting_error
  dsn = @sentry_dsn
  unless dsn.empty?
    why = SentryDsn.problem(dsn)
    return "sentry_dsn must look like https://<public key>@<host>/<project id>: #{why}" unless why.empty?
  end
  text = @error_sample_rate_text
  rate = @error_sample_rate
  in_range = rate >= 0.0 && rate <= 1.0
  unless text.empty?
    return "" if Config.rate_text?(text) && in_range

    shown = text.bytesize > 20 ? "#{text.byteslice(0, 20).to_s}..." : text
    return "error_sample_rate must be a number from 0.0 to 1.0 (got #{shown.inspect})"
  end
  return "" if in_range

  "error_sample_rate must be a number from 0.0 to 1.0 (got #{rate})"
end

#secure_cookies? ⇒ Boolean

Whether cookies are written Secure: #session_secure, or #force_ssl (every request is https then).

Returns:

  • (Boolean)


1516
1517
1518
# File 'cybertrain/config.rb', line 1516

def secure_cookies?
  @session_secure || @force_ssl
end

#set_bool_setting(name, value) ⇒ nil

Replaces the value of a declared boolean setting, for tests.

Parameters:

  • name (Symbol)
  • value (Boolean)

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when no boolean setting of that name is declared



1726
1727
1728
1729
1730
# File 'cybertrain/config.rb', line 1726

def set_bool_setting(name, value)
  bool_setting(name)
  @setting_bools[name.to_s] = value
  nil
end

#set_int_setting(name, value) ⇒ nil

Replaces the value of a declared Integer setting, for tests. The declared bounds are not applied.

Parameters:

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when no Integer setting of that name is declared



1714
1715
1716
1717
1718
# File 'cybertrain/config.rb', line 1714

def set_int_setting(name, value)
  int_setting(name)
  @setting_ints[name.to_s] = value
  nil
end

#set_string_setting(name, value) ⇒ nil

Replaces the value of a declared String setting, for tests.

Parameters:

  • name (Symbol)
  • value (String)

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when no String setting of that name is declared



1701
1702
1703
1704
1705
# File 'cybertrain/config.rb', line 1701

def set_string_setting(name, value)
  string_setting(name)
  @setting_strings[name.to_s] = value
  nil
end

#setting_bool(name, env:, default:) ⇒ nil

Declares an application setting holding true or false, read once from the environment variable env: 1 or true is true, 0 or false is false, an empty or unset variable means default, and any other value gives default with a WARN line through Cybertrain.logger. Read it with #bool_setting.

Examples:

config/app.rb

c.setting_bool :worker, env: "MYAPP_WORKER", default: true

Parameters:

  • name (Symbol)
  • env (String) —

    the environment variable

  • default (Boolean)

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when the name is already declared or env is empty



1652
1653
1654
1655
1656
1657
# File 'cybertrain/config.rb', line 1652

def setting_bool(name, env:, default:)
  key = declare_setting(name, env, false)
  @setting_bools[key] = Config.bool_from_env(env, default)
  @setting_descriptions[key] = "boolean (1/true, 0/false), default #{default}"
  nil
end

#setting_int(name, env:, default:, min: SETTING_INT_MIN, max: SETTING_INT_MAX) ⇒ nil

Declares an application setting holding an Integer, read once from the environment variable env: decimal digits with an optional leading -, within min..max. An empty or unset variable means default; anything else that does not parse, or a number out of bounds, also gives default, with a WARN line through Cybertrain.logger. Read it with #int_setting.

Examples:

config/app.rb

c.setting_int :prune_interval, env: "MYAPP_PRUNE_INTERVAL", default: 3600, min: 1, max: 9_999_999

Parameters:

  • name (Symbol)
  • env (String) —

    the environment variable

  • default (Integer)
  • min (Integer) (defaults to: SETTING_INT_MIN) —

    the smallest accepted value (no bound by default)

  • max (Integer) (defaults to: SETTING_INT_MAX) —

    the largest accepted value (no bound by default)

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when the name is already declared, env is empty, or default is outside min..max



1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
# File 'cybertrain/config.rb', line 1626

def setting_int(name, env:, default:, min: SETTING_INT_MIN, max: SETTING_INT_MAX)
  key = name.to_s
  bounds = Config.int_bounds(min, max)
  if min > max || default < min || default > max
    raise ArgumentError, "setting #{key}: default #{default} is out of range (#{bounds})"
  end

  declare_setting(name, env, false)
  @setting_ints[key] = Config.int_from_env(env, default, min, max)
  @setting_descriptions[key] = bounds.empty? ? "integer, default #{default}" : "integer #{bounds}, default #{default}"
  nil
end

#setting_string(name, env:, default:, secret: false) ⇒ nil

Declares an application setting holding a String, read once from the environment variable env (an empty or unset variable means default). Read it with #string_setting. A name may be declared once; give it as a Symbol. secret: true keeps the value out of the boot banner and help, which then show only the variable’s name.

Examples:

config/app.rb

Cybertrain.configure do |c|
  c.setting_string :base_url, env: "MYAPP_BASE_URL", default: ""
  c.setting_string :smtp_password, env: "MYAPP_SMTP_PASSWORD", default: "", secret: true
end
Cybertrain.config.string_setting(:base_url)

Parameters:

  • name (Symbol)
  • env (String) —

    the environment variable

  • default (String)
  • secret (Boolean) (defaults to: false)

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    when the name is already declared or env is empty



1602
1603
1604
1605
1606
1607
# File 'cybertrain/config.rb', line 1602

def setting_string(name, env:, default:, secret: false)
  key = declare_setting(name, env, secret)
  @setting_strings[key] = Config.env_or(env, default)
  @setting_descriptions[key] = secret ? "string, secret" : "string, default #{default.inspect}"
  nil
end

#string_setting(name) ⇒ String

The value of the String setting name (#setting_string).

Parameters:

  • name (Symbol)

Returns:

  • (String)

Raises:

  • (ArgumentError) —

    when no String setting of that name is declared



1664
1665
1666
1667
1668
1669
# File 'cybertrain/config.rb', line 1664

def string_setting(name)
  key = name.to_s
  raise ArgumentError, "no string setting #{key} (declare it with setting_string)" unless @setting_strings.key?(key)

  @setting_strings[key].to_s
end

#test? ⇒ Boolean

Returns:

  • (Boolean)


1568
1569
1570
# File 'cybertrain/config.rb', line 1568

def test?
  @env == "test"
end

#time_zone_error ⇒ String

The error Application#boot reports when time_zone is not a zone TimeZone can load from the system zoneinfo; “” when it is. Asked before scheduler_error, so an unknown time_zone that scheduler_tz follows is reported once, under its own name.

Returns:

  • (String)


227
228
229
230
231
232
# File 'cybertrain/config/validation.rb', line 227

def time_zone_error
  zone_name = @time_zone
  return "time_zone #{zone_name.inspect} is not a known time zone" unless TimeZone.find(zone_name).found?

  ""
end

#validation_error ⇒ String

The first problem boot would refuse to start with, “” when the configuration is usable. The areas in the order boot has always reported them, after the log settings: the session cookie and CSRF, the request and upload limits, the time zone, the background work, pagination, the proxies, the health check, the feeds, the stream endpoint, the locales, the authentication limits, the mail delivery method, error reporting, the security headers and the encryption keys. Reads only; safe to call from a test or a --check-style command with no database and no writable disk.

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'cybertrain/config/validation.rb', line 26

def validation_error
  problem = log_error
  return problem unless problem.empty?

  problem = session_same_site_error
  return problem unless problem.empty?

  problem = csrf_exempt_prefixes_error
  return problem unless problem.empty?

  problem = max_body_bytes_error
  return problem unless problem.empty?

  problem = upload_limits_error
  return problem unless problem.empty?

  problem = time_zone_error
  return problem unless problem.empty?

  problem = scheduler_error
  return problem unless problem.empty?

  problem = max_page_error
  return problem unless problem.empty?

  problem = trusted_proxies_error
  return problem unless problem.empty?

  problem = health_error
  return problem unless problem.empty?

  problem = feeds_error
  return problem unless problem.empty?

  problem = stream_error
  return problem unless problem.empty?

  problem = i18n_error
  return problem unless problem.empty?

  problem = auth_error
  return problem unless problem.empty?

  problem = mail_delivery_error
  return problem unless problem.empty?

  problem = reporting_error
  return problem unless problem.empty?

  problem = security_error
  return problem unless problem.empty?

  encryption_error
end