|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | /**
|
10 |
| - * Just a special kind of dictionary. The `Express` application class is |
| 10 | + * Just a special kind of dictionary. The ``Express`` application class is |
11 | 11 | * currently the sole example.
|
12 | 12 | *
|
13 | 13 | * Examples:
|
| 14 | + * ```swift |
| 15 | + * app.set("env", "production") |
| 16 | + * app.enable("x-powered-by") |
14 | 17 | *
|
15 |
| - * app.set("env", "production") |
16 |
| - * app.enable("x-powered-by") |
17 |
| - * |
18 |
| - * let env = app.settings.env |
| 18 | + * let env = app.settings.env |
| 19 | + * ``` |
19 | 20 | */
|
20 | 21 | public protocol SettingsHolder {
|
21 | 22 |
|
22 |
| - func set(_ key: String, _ value: Any?) |
| 23 | + /** |
| 24 | + * Sets or removes a configuration key in the settings store. |
| 25 | + * |
| 26 | + * Example: |
| 27 | + * ```swift |
| 28 | + * app.set("view engine", "html") |
| 29 | + * .set("views", __dirname() + "/views") |
| 30 | + * .enable("x-powered-by") |
| 31 | + * ``` |
| 32 | + * |
| 33 | + * - Parameters: |
| 34 | + * - key: The name of the key, e.g. "view engine" |
| 35 | + * - value: The associated value, if `nil` is passed in, the value is |
| 36 | + * removed from the store. |
| 37 | + * - Returns: `self` for chaining. |
| 38 | + */ |
| 39 | + @discardableResult |
| 40 | + func set(_ key: String, _ value: Any?) -> Self |
| 41 | + |
| 42 | + /** |
| 43 | + * Returns the value of a configuration key from the settings store. |
| 44 | + * |
| 45 | + * Example: |
| 46 | + * ```swift |
| 47 | + * let engine = app.get("view engine") |
| 48 | + * ``` |
| 49 | + * |
| 50 | + * - Parameters: |
| 51 | + * - key: The name of the key, e.g. "view engine" |
| 52 | + * - Returns: The value in the store, or `nil` if missing. |
| 53 | + */ |
23 | 54 | func get(_ key: String) -> Any?
|
24 | 55 | }
|
25 | 56 |
|
26 | 57 | public extension SettingsHolder {
|
27 | 58 |
|
| 59 | + /** |
| 60 | + * Set configuration key in the settings store to `true`. |
| 61 | + * |
| 62 | + * Example: |
| 63 | + * ```swift |
| 64 | + * app.enable("x-powered-by") |
| 65 | + * ``` |
| 66 | + * |
| 67 | + * - Parameters: |
| 68 | + * - key: The name of the bool key, e.g. "view engine" |
| 69 | + * - Returns: `self` for chaining. |
| 70 | + */ |
28 | 71 | @inlinable
|
29 |
| - func enable(_ key: String) { |
30 |
| - set(key, true) |
| 72 | + @discardableResult |
| 73 | + func enable(_ key: String) -> Self { |
| 74 | + return set(key, true) |
31 | 75 | }
|
| 76 | + |
| 77 | + /** |
| 78 | + * Set configuration key in the settings store to `false`. |
| 79 | + * |
| 80 | + * Example: |
| 81 | + * ```swift |
| 82 | + * app.disable("x-powered-by") |
| 83 | + * ``` |
| 84 | + * |
| 85 | + * - Parameters: |
| 86 | + * - key: The name of the bool key, e.g. "view engine" |
| 87 | + * - Returns: `self` for chaining. |
| 88 | + */ |
32 | 89 | @inlinable
|
33 |
| - func disable(_ key: String) { |
34 |
| - set(key, false) |
| 90 | + @discardableResult |
| 91 | + func disable(_ key: String) -> Self { |
| 92 | + return set(key, false) |
35 | 93 | }
|
36 | 94 |
|
37 | 95 | @inlinable
|
|
0 commit comments