const_conf 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bd3638ecc438cef844c87bf0cceeaa962a6863091724d71c3f8f278bada70f6
4
- data.tar.gz: bd088bffdd006036e972c563d7551fa487b715e44b22a245e4071faa511d246c
3
+ metadata.gz: 783442195899da65976c312008a1dbc0277e523159702d8582e5933a1f40750c
4
+ data.tar.gz: a019c8c9d8b0eaa6eebe12ce15a5a3772d47bbec121a0eb7c323de25e13edc59
5
5
  SHA512:
6
- metadata.gz: 9f3909e1e564af3d3fc333d32e07f533642e5d2cac974beb0fb4479417621bc43a13e31a833d83889fa55fb900bbe105e839197385026431ac0cae90cdd22d1d
7
- data.tar.gz: 740272c69d8b046e08131c80d9df806dd12eb12939f6256e357a4815157cc6878cae076eba4835395d4bf271f59fa948e63c22311faf169036d70070db785ff4
6
+ metadata.gz: 1a9b3cc846abe1a7196bae1d51090349be3de081e80ce733a4ea947f66026f53f4cd99893d2144c17917b78c56c149e28382e63a8046b65b0f51f08325450f9b
7
+ data.tar.gz: d7331a496fd34232f3986f1d5940a8af108c2ff965c4e2af7d800acc3b1eda109424234f727cdc5260d82c89a84e0f52be4d3babf4c57b20b39cff85e6b25f64
data/CHANGES.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-08-20 v0.8.2
4
+
5
+ * Documented block calling contexts for `decode`, `required`, and `check` in
6
+ the README, clarifying differences between plain `Proc` calls and
7
+ `instance_eval` within the `Setting` context.
8
+ * Improved test result feedback by adding emoji-based status messages and
9
+ descriptive cleanup steps, including conditional checks using the `RESULT`
10
+ variable and cleaner file deletion commands.
11
+ * Updated setting validation documentation to clarify `instance_eval` arity
12
+ rules for the `check` block, fixed typos in `required?` and `sensitive`
13
+ accessor descriptions, and clarified that `sensitive` masks values in
14
+ `view` output.
15
+ * Corrected guidance for guarding absent values to use `value.blank?` instead
16
+ of `value.nil?`.
17
+ * Rewrote the `?` predicate section in the README to explain the `FOO::BAR`
18
+ (constant) and `FOO::BAR?` (predicate) access pattern, and added a "How
19
+ concepts compose" section with a scenario table for `confirm!`, constants,
20
+ and predicates.
21
+ * Fixed a typo in the README truthy value description, correcting "truty" to
22
+ `truthy`.
23
+ * Added a YARD note to `ConstConf::Setting#checked?` explaining that it is
24
+ evaluated unconditionally in `ConstConf::Setting#confirm!`, even when no
25
+ value is supplied.
26
+ * Clarified the distinction between `required` and blank values in the
27
+ README, noting that `required true` only guards against `nil`, and updated
28
+ the `@raise` YARD doc for `ConstConf::RequiredValueNotConfigured` to
29
+ explicitly state that blank values satisfy the check.
30
+
3
31
  ## 2026-08-04 v0.8.1
4
32
 
5
33
  ### Changed
data/README.md CHANGED
@@ -99,8 +99,18 @@ end
99
99
 
100
100
  ### Note that **Predicate Methods (`?`)** are defined
101
101
 
102
- If a setting is `active?`, the predicate method returns a truthy value, which
103
- then can be used like this:
102
+ For each setting, ConstConf defines a deliberate pair:
103
+
104
+ - **`FOO::BAR`** — the constant. Holds the resolved value from `ENV` or
105
+ `default`. Always returns whatever was configured (or `nil`). This is
106
+ what the environment variable *is*.
107
+ - **`FOO::BAR?`** — the predicate. Returns the value *only if* `active?`
108
+ is true; otherwise returns `nil`. This is what your code is *allowed to
109
+ use*.
110
+
111
+ They share the same name because they share the same source. The predicate
112
+ is an opt-in gate on the constant, letting you evaluate the configuration
113
+ conditionally:
104
114
 
105
115
  ```ruby
106
116
  # Check if active?
@@ -111,7 +121,8 @@ else
111
121
  end
112
122
  ```
113
123
 
114
- Or `nil` is returned, which can then be handled accordingly.
124
+ When `active?` is false (value is `nil` or blank under the default
125
+ `:present?` activation), the predicate short-circuits to `nil`.
115
126
 
116
127
  ### Note that **Getter Methods (`!`)** are also defined
117
128
 
@@ -158,7 +169,7 @@ Key indicators in the view:
158
169
  | 🔴 | ⚪ | Required settings that must be configured|
159
170
  | 🔧 | ⚪ | Configured values from ENV |
160
171
  | 🙈 | ⚪ | ENV var was ignored |
161
- | 🟢 | ⚪ | Setting is active (? method returns truty value) |
172
+ | 🟢 | ⚪ | Setting is active (? method returns truthy value) |
162
173
  | ⚙️ | ⚪ | Decoding logic applied to transform raw input |
163
174
  | ✅ ┊ ☑️ | ❌ | Validation checks have passed or failed |
164
175
 
@@ -357,6 +368,10 @@ functionality.
357
368
  - **Usage**: `decode(&:chomp)` removes whitespace, `decode { YAML.load(it) }`
358
369
  parses YAML
359
370
  - **Indicator**: Shows ⚙️ in view output when active
371
+ - **Block context**: Unlike `check`, the decode block is called as a plain
372
+ Proc (`decode.(raw_value)`). The block receives the raw (pre-decode) value
373
+ from the environment variable or default. Use `it` or a block parameter to
374
+ access the value.
360
375
 
361
376
  #### **Required** (`required?`)
362
377
 
@@ -366,6 +381,14 @@ functionality.
366
381
  - **Usage**: `required true` (always required) or `required { !Rails.env.test?
367
382
  }` (conditional)
368
383
  - **Indicator**: Shows 🔴 in view output when required and not satisfied
384
+ - **Note**: `required true` only guards against `nil`. A blank string like
385
+ `""` will pass `confirm!` but cause the `?` predicate to return `nil`.
386
+ Use `check { value.present? }` or `required ->(v) { v.present? }` if you
387
+ need non-blank validation.
388
+ - **Block context**: A Proc-based `required` is called with the raw
389
+ (pre-decode) value when arity is 1: `required ->(v) { v.present? }`.
390
+ An arity-0 Proc runs without arguments:
391
+ `required { !Rails.env.test? }`.
369
392
 
370
393
  #### **Configured** (`configured?`)
371
394
 
@@ -385,6 +408,13 @@ functionality.
385
408
  - **☑️** = No custom check defined (passes by default - `:unchecked_true`)
386
409
  - **✅** = Custom check explicitly passes (returns `true`)
387
410
  - **❌** = Custom check explicitly fails (returns `false`)
411
+ - **Note**: `checked?` is evaluated unconditionally in `confirm!`, even
412
+ when no value is supplied. If your check should pass for absent values,
413
+ guard with `value.nil? ||`.
414
+ - **Block context**: The check block is evaluated via `instance_eval` in the
415
+ Setting's context, so bare method calls like `value` and `configured?`
416
+ resolve to this setting. An arity-1 block (`->(s) { ... }`) also receives
417
+ the Setting instance as its argument.
388
418
 
389
419
  #### **Active** (`active?`)
390
420
 
@@ -409,6 +439,42 @@ These concepts work together to provide a comprehensive configuration
409
439
  management system that tracks the complete lifecycle and status of each setting
410
440
  from definition through validation and usage.
411
441
 
442
+ ### How concepts compose
443
+
444
+ `FOO::BAR?` is defined as `(setting.value if setting.active?)`. So it returns
445
+ a truthy value only when `active?` is true *and* `value` is truthy. With the
446
+ default `activated` of `:present?`, that means the resolved value must be
447
+ non-nil and non-blank.
448
+
449
+ This is a different question from `confirm!`. At definition time, `confirm!`
450
+ asks: "did you supply a non-nil value?" (`required` + `value_provided?`).
451
+ At usage time, `FOO::BAR?` asks: "is this value actually usable?" (`active?`).
452
+ A setting can pass `confirm!` (value exists) yet `FOO::BAR?` still returns
453
+ `nil` (value is blank). These are independent axes, not redundant ones.
454
+
455
+ For example:
456
+
457
+ ```ruby
458
+ module FOO
459
+ include ConstConf
460
+ description 'Foo config'
461
+
462
+ BAR = set do
463
+ description 'A bar setting'
464
+ required true
465
+ end
466
+ end
467
+ ```
468
+
469
+ | Scenario | `confirm!` | `FOO::BAR` | `FOO::BAR?` |
470
+ |---|---|---|---|
471
+ | `ENV['FOO_BAR']` unset | ❌ raises `RequiredValueNotConfigured` | — | — |
472
+ | `ENV['FOO_BAR'] = ""` | ✅ passes (non-nil) | `""` | `nil` (blank → not active) |
473
+ | `ENV['FOO_BAR'] = "hello"` | ✅ passes | `"hello"` | `"hello"` |
474
+
475
+ This shows how `required`, `check`, and `active?` each guard a different
476
+ aspect: existence, validity, and usability.
477
+
412
478
  ### Advanced Usage Examples
413
479
 
414
480
  #### Nested Configuration Modules
data/const_conf.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: const_conf 0.8.1 ruby lib
2
+ # stub: const_conf 0.8.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "const_conf".freeze
6
- s.version = "0.8.1".freeze
6
+ s.version = "0.8.2".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -92,16 +92,32 @@ class ConstConf::Setting
92
92
  # validate that a setting meets certain criteria beyond basic required and
93
93
  # default value checks. The check can be a Proc that evaluates to true,
94
94
  # :unchecked_true (truthy), or false, allowing for custom validation logic. It
95
- # deffaults to true, if not set otherwise.
95
+ # defaults to true, if not set otherwise.
96
96
  #
97
97
  # @return [Proc, Object] the current check configuration value
98
98
  setting_accessor :check, -> setting { :unchecked_true }
99
99
 
100
100
  # Checks if the configuration setting passes its validation check.
101
101
  #
102
+ # The check block is evaluated via {#instance_eval} in the context of this
103
+ # Setting instance, so bare method calls (e.g. `value`, `configured?`)
104
+ # resolve to this setting. Standard Ruby `instance_eval` arity rules apply:
105
+ #
106
+ # - **Arity 0**: The block runs with `self` set to this Setting instance
107
+ # and receives no arguments. Access setting properties directly:
108
+ # `check { value.blank? || value.scheme == 'redis' }`
109
+ #
110
+ # - **Arity 1**: The block receives this Setting instance as its sole
111
+ # argument as well. Use it when you prefer explicit receiver access:
112
+ # `check ->(s) { s.value.blank? || s.value.scheme == 'redis' }`
113
+ #
114
+ # Note: {#checked?} is evaluated unconditionally in {#confirm!}, even when
115
+ # no value is supplied. If your check should pass for absent values, guard
116
+ # with `value.blank? ||`.
117
+ #
102
118
  # @return [Boolean, Symbol] true if the setting's check logic evaluates to
103
- # true, # false or false if not. I no check was defined, returns
104
- # :unchecked_true. @see check
119
+ # true, false if not. If no check was defined, returns
120
+ # :unchecked_true. @see check
105
121
  def checked?
106
122
  instance_eval(&check)
107
123
  end
@@ -124,8 +140,8 @@ class ConstConf::Setting
124
140
  # * With arity 0: Called without arguments (e.g., `-> {
125
141
  # some_value.present? }`)
126
142
  # @return [Boolean, Proc] returns the value that was set
127
- # @method required(value = nil, &block)
128
- # @see #required?
143
+ # @method required(value = nil, &block)
144
+ # @see #required?
129
145
  setting_accessor :required, false
130
146
 
131
147
  # Checks if the setting has a required value configured or as a default
@@ -151,10 +167,13 @@ class ConstConf::Setting
151
167
  end
152
168
  end
153
169
 
154
- # Checks if the setting has a required value configured.
170
+ # Sets or retrieves the sensitive flag for the configuration setting.
155
171
  #
156
- # @return [Boolean] true if the setting is marked as required and has a valid
157
- # value, false otherwise
172
+ # When true, the setting's value is masked as 🤫 in the {#view} output
173
+ # to protect confidential data such as passwords, API keys, and tokens.
174
+ #
175
+ # @param value [Boolean] true to mark the setting as sensitive
176
+ # @return [Boolean] the current sensitivity flag
158
177
  setting_accessor :sensitive, false
159
178
 
160
179
  alias sensitive? sensitive
@@ -300,8 +319,10 @@ class ConstConf::Setting
300
319
  #
301
320
  # @raise [ ConstConf::RequiredDescriptionNotConfigured ] if the setting's description
302
321
  # is blank or the parent module's description is missing
303
- # @raise [ ConstConf::RequiredValueNotConfigured ] if the setting is required but no
304
- # value is provided
322
+ # @raise [ ConstConf::RequiredValueNotConfigured ] if the setting is required
323
+ # but no non-nil value is provided. Note that blank values (e.g. `""` or
324
+ # `" "`) satisfy this check; use {#check} or a Proc-based {#required}
325
+ # to also reject them.
305
326
  # @raise [ ConstConf::SettingCheckFailed ] if the setting's check fails
306
327
  def confirm!
307
328
  if parent_namespace.is_a?(Module) && parent_namespace < ConstConf
@@ -1,6 +1,6 @@
1
1
  module ConstConf
2
2
  # ConstConf version
3
- VERSION = '0.8.1'
3
+ VERSION = '0.8.2'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: const_conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank