1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
require "pathname"
module ProTacts
# Single source of truth for configuration read from the environment.
# Nothing else in the app should read ENV directly; add a method here and
# read it through ProTacts.config instead.
class Config
# @rbs @env: Hash[String, String]
TRUTHY = /\A(1|true|yes)\z/i #: Regexp
#: (?Hash[String, String] env) -> void
def initialize(env = ENV)
@env = env
end
# Sentry DSN; nil when unset. A nil DSN is passed straight to
# Sentry.init, which leaves the client inert — capture_message and
# the rack middleware become no-ops.
#: () -> String?
def sentry_dsn
@env.fetch("SENTRY_DSN", nil)
end
# Whether to dump full request/response exchanges to the log. Off by
# default because it logs contact data. See ProTacts::DebugLogger.
#: () -> bool
def debug?
value = @env.fetch("PRO_TACTS_DEBUG", nil)
!value.nil? && value.match?(TRUTHY)
end
# Root data directory: holds the contacts directory and, later, the
# database. Overridable with PRO_TACTS_DATA_DIR.
#: () -> Pathname
def data_dir
Pathname.new(@env.fetch("PRO_TACTS_DATA_DIR", "data"))
end
# Contacts live at data/contacts, one KDL file per contact; the
# filename is the contact ID. See
# docs/plans/2026-01-12-carddav-architecture.md.
#: () -> Pathname
def contacts_dir
data_dir / "contacts"
end
# Where requests the app could not answer are kept, one directory per
# distinct request. Under log/ because it holds request data and is not
# meant to be committed. See ProTacts::UnhandledRequests.
#: () -> Pathname
def unhandled_dir
Pathname.new(@env.fetch("PRO_TACTS_UNHANDLED_DIR", "log/unhandled"))
end
# Where the debug logger writes. A path, overridable with
# PRO_TACTS_DEBUG_LOG; "stderr" keeps it on the process's stderr.
#: () -> String
def debug_log_path
@env.fetch("PRO_TACTS_DEBUG_LOG", "log/debug.log")
end
end
end