Class: ConvertSdk::Sentinel
- Inherits:
-
Object
- Object
- ConvertSdk::Sentinel
- Defined in:
- lib/convert_sdk/sentinel.rb
Overview
A frozen singleton sentinel — the SDK's public contract for a business miss.
Bucketing and feature decisions that find no answer (no data, not enough data, no variation decided) return a +Sentinel+ singleton rather than raising or returning a bare +nil+. This is architecture Decision 2: misses are signaled by value, never by exception.
The protocol a +Sentinel+ implements:
- +#to_s+ — the byte-identical JS wire string (appears in payloads/logs).
- +#key+ — always +nil+, so the documented integrator pattern +case variation&.key+ falls through to the +else+ branch on a miss.
- +#error?+ — always +true+, the value-object discriminator that distinguishes a sentinel from a real BucketedVariation/BucketedFeature (both +false+).
Sentinels are exposed as frozen singleton constants (e.g. RuleError::NO_DATA_FOUND), so callers can branch on object identity for granular handling:
result = context.run_experience("homepage-test") case result.key when nil # a miss — inspect which one via identity show_default if result.equal?(ConvertSdk::RuleError::NO_DATA_FOUND) else render_variation(result.key) end
Equality is intentionally left as default object identity (no +==+ override): two distinct +Sentinel+ instances built from the same wire string are NOT equal, which is why the canonical instances live as shared frozen constants.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Always true — a sentinel always signals a business miss.
-
#initialize(wire_string) ⇒ Sentinel
constructor
A new instance of Sentinel.
-
#key ⇒ nil
Always nil, so +case variation&.key+ falls through to else.
-
#to_s ⇒ String
The byte-identical JS wire string.
Constructor Details
#initialize(wire_string) ⇒ Sentinel
Returns a new instance of Sentinel.
37 38 39 40 |
# File 'lib/convert_sdk/sentinel.rb', line 37 def initialize(wire_string) @wire_string = wire_string.dup.freeze freeze end |
Instance Method Details
#error? ⇒ Boolean
Returns always true — a sentinel always signals a business miss.
53 54 55 |
# File 'lib/convert_sdk/sentinel.rb', line 53 def error? true end |
#key ⇒ nil
Returns always nil, so +case variation&.key+ falls through to else.
48 49 50 |
# File 'lib/convert_sdk/sentinel.rb', line 48 def key nil end |
#to_s ⇒ String
Returns the byte-identical JS wire string.
43 44 45 |
# File 'lib/convert_sdk/sentinel.rb', line 43 def to_s @wire_string end |