Skip to content

Commit ecf9668

Browse files
committed
just use one config
1 parent 4b0dd6f commit ecf9668

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

docs/design.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ require "hooks-ruby"
8080

8181
# Returns a Rack-compatible app
8282
app = Hooks.build(
83-
config: "/path/to/endpoints/", # Directory or Array/Hash
84-
settings: "/path/to/settings.yaml", # YAML, JSON, or Hash
83+
config: "/path/to/config.yaml", # YAML, JSON, or Hash
8584
log: MyCustomLogger.new, # Optional logger (must respond to #info, #error, etc.)
8685
request_limit: 1_048_576, # Default max body size (bytes)
87-
request_timeout: 15, # Default timeout (seconds)
88-
root_path: "/webhooks" # Default mount prefix
86+
request_timeout: 15, # Default timeout (seconds)
87+
root_path: "/webhooks" # Default mount prefix
8988
)
9089
```
9190

@@ -101,10 +100,9 @@ Core configuration options can be provided via environment variables:
101100

102101
```bash
103102
# Core configuration
104-
export HOOKS_CONFIG_DIR=./config/endpoints
105-
export HOOKS_SETTINGS=./config/settings.yaml
103+
export HOOKS_CONFIG=./config/config.yaml
106104

107-
# Runtime settings (override settings file)
105+
# Runtime settings (override config file)
108106
export HOOKS_REQUEST_LIMIT=1048576
109107
export HOOKS_REQUEST_TIMEOUT=15
110108
export HOOKS_GRACEFUL_SHUTDOWN_TIMEOUT=30
@@ -124,7 +122,7 @@ ruby -r hooks-ruby -e "run Hooks.build"
124122
```
125123

126124
> **Hello-World Mode**
127-
> If invoked without `config` or `settings`, serves `GET <root_path>/hello`:
125+
> If invoked without `config`, serves `GET <root_path>/hello`:
128126
>
129127
> ```json
130128
> { "message": "Hooks is working!" }
@@ -144,7 +142,6 @@ lib/hooks/
144142
├── core/
145143
│ ├── builder.rb # Hooks.build: config loading, validation, signal handling - builds a rack compatible app
146144
│ ├── config_loader.rb # Loads + merges per-endpoint configs
147-
│ ├── settings_loader.rb # Loads global settings
148145
│ ├── config_validator.rb # Dry::Schema-based validation
149146
│ ├── logger_factory.rb # Structured JSON logger + context enrichment
150147
│ ├── metrics_emitter.rb # Event emitter for request metrics
@@ -186,10 +183,10 @@ opts: # Freeform user-defined options
186183
teams: ["infra","billing"]
187184
```
188185
189-
### 5.2 Global Settings Config
186+
### 5.2 Global Config File
190187
191188
```yaml
192-
# config/settings.yaml
189+
# config/config.yaml
193190
handler_dir: ./handlers # handler class directory
194191
log_level: info # debug | info | warn | error
195192

@@ -205,6 +202,7 @@ version_path: /version # gem version endpoint
205202

206203
# Runtime behavior
207204
environment: production # development | production
205+
endpoints_dir: ./config/endpoints # directory containing endpoint configs
208206
```
209207
210208
---
@@ -213,7 +211,7 @@ environment: production # development | production
213211
214212
1. **Builder (`core/builder.rb`)**
215213

216-
* Load settings (env or file) via `settings_loader`
214+
* Load config (env or file) via `config_loader`
217215
* Load endpoint configs via `config_loader`
218216
* Validate via `config_validator` (Dry::Schema); halt if invalid at boot
219217
* Initialize structured JSON logger via `logger_factory`
@@ -344,16 +342,16 @@ Configuration is loaded and merged in the following priority order (highest to l
344342

345343
1. **Programmatic parameters** passed to `Hooks.build(...)`
346344
2. **Environment variables** (`HOOKS_*`)
347-
3. **Settings file** (YAML/JSON)
345+
3. **Config file** (YAML/JSON)
348346
4. **Built-in defaults**
349347

350348
**Example:**
351349

352350
```ruby
353351
# This programmatic setting will override ENV and file settings
354352
app = Hooks.build(
355-
request_timeout: 30, # Overrides HOOKS_REQUEST_TIMEOUT and settings.yaml
356-
settings: "./config/settings.yaml"
353+
request_timeout: 30, # Overrides HOOKS_REQUEST_TIMEOUT and config.yaml
354+
config: "./config/config.yaml"
357355
)
358356
```
359357

@@ -407,20 +405,19 @@ hooks serve [options]
407405
* `-p`, `--port PORT` — Port to listen on (default: 3000)
408406
* `-b`, `--bind HOST` — Bind address (default: 0.0.0.0)
409407
* `-e`, `--env ENV` — Environment (default: production)
410-
* `-c`, `--config PATH` — Path to endpoints config directory
411-
* `-s`, `--settings PATH` — Path to global settings file
408+
* `-c`, `--config PATH` — Path to config file (YAML/JSON)
412409
* `--no-puma` — (Advanced) Use the default Rack handler instead of Puma
413410
* `-h`, `--help` — Show help message
414411

415412
### Example
416413

417414
```bash
418-
hooks serve -p 8080 -c ./config/endpoints -s ./config/settings.yaml
415+
hooks serve -p 8080 -c ./config/config.yaml
419416
```
420417

421418
### How it Works
422419

423-
* The CLI loads configuration and settings from CLI args, ENV, or defaults.
420+
* The CLI loads configuration from CLI args, ENV, or defaults.
424421
* It builds the Rack app using `Hooks.build(...)`.
425422
* By default, it starts the server using Puma (via `Rack::Handler::Puma`).
426423
* If Puma is not available, it falls back to the default Rack handler (e.g., WEBrick), but Puma is strongly recommended and included as a dependency.
@@ -436,8 +433,7 @@ options = {
436433
port: ENV.fetch("PORT", 3000),
437434
bind: ENV.fetch("BIND", "0.0.0.0"),
438435
env: ENV.fetch("RACK_ENV", "production"),
439-
config: ENV["HOOKS_CONFIG_DIR"] || "./config/endpoints",
440-
settings: ENV["HOOKS_SETTINGS"] || "./config/settings.yaml",
436+
config: ENV["HOOKS_CONFIG"] || "./config/config.yaml",
441437
use_puma: true
442438
}
443439
@@ -446,13 +442,12 @@ OptionParser.new do |opts|
446442
opts.on("-pPORT", "--port=PORT", Integer, "Port to listen on") { |v| options[:port] = v }
447443
opts.on("-bHOST", "--bind=HOST", String, "Bind address") { |v| options[:bind] = v }
448444
opts.on("-eENV", "--env=ENV", String, "Environment") { |v| options[:env] = v }
449-
opts.on("-cPATH", "--config=PATH", String, "Endpoints config directory") { |v| options[:config] = v }
450-
opts.on("-sPATH", "--settings=PATH", String, "Settings file") { |v| options[:settings] = v }
445+
opts.on("-cPATH", "--config=PATH", String, "Config file (YAML/JSON)") { |v| options[:config] = v }
451446
opts.on("--no-puma", "Use default Rack handler instead of Puma") { options[:use_puma] = false }
452447
opts.on("-h", "--help", "Show help") { puts opts; exit }
453448
end.parse!(ARGV)
454449
455-
app = Hooks.build(config: options[:config], settings: options[:settings])
450+
app = Hooks.build(config: options[:config])
456451
457452
if options[:use_puma]
458453
require "rack/handler/puma"

0 commit comments

Comments
 (0)