Class: Subflag::Rails::EvaluationResult
- Inherits:
-
Object
- Object
- Subflag::Rails::EvaluationResult
- Defined in:
- lib/subflag/rails/evaluation_result.rb
Overview
Result of a flag evaluation with full details
Instance Attribute Summary collapse
-
#error_code ⇒ Symbol?
readonly
Error code if evaluation failed.
-
#error_message ⇒ String?
readonly
Error message if evaluation failed.
-
#flag_key ⇒ String
readonly
The flag key that was evaluated.
-
#reason ⇒ Symbol
readonly
The reason for this evaluation result Possible values: :default, :targeting_match, :static, :split, :error, :unknown.
-
#value ⇒ Object
readonly
The resolved flag value.
-
#variant ⇒ String?
readonly
The variant name that was selected.
Class Method Summary collapse
-
.from_openfeature(details, flag_key:) ⇒ EvaluationResult
Build from OpenFeature evaluation details.
-
.from_subflag(result) ⇒ EvaluationResult
Build from Subflag::EvaluationResult (from Ruby provider).
Instance Method Summary collapse
-
#default? ⇒ Boolean
Check if the default value was returned.
-
#error? ⇒ Boolean
Check if there was an error during evaluation.
-
#initialize(value:, variant: nil, reason: :unknown, flag_key:, error_code: nil, error_message: nil) ⇒ EvaluationResult
constructor
A new instance of EvaluationResult.
-
#targeted? ⇒ Boolean
Check if the value came from targeting rules.
-
#to_h ⇒ Hash
Convert to hash representation.
Constructor Details
#initialize(value:, variant: nil, reason: :unknown, flag_key:, error_code: nil, error_message: nil) ⇒ EvaluationResult
Returns a new instance of EvaluationResult.
36 37 38 39 40 41 42 43 |
# File 'lib/subflag/rails/evaluation_result.rb', line 36 def initialize(value:, variant: nil, reason: :unknown, flag_key:, error_code: nil, error_message: nil) @value = value @variant = variant @reason = reason @flag_key = flag_key @error_code = error_code @error_message = end |
Instance Attribute Details
#error_code ⇒ Symbol? (readonly)
Returns Error code if evaluation failed.
31 32 33 |
# File 'lib/subflag/rails/evaluation_result.rb', line 31 def error_code @error_code end |
#error_message ⇒ String? (readonly)
Returns Error message if evaluation failed.
34 35 36 |
# File 'lib/subflag/rails/evaluation_result.rb', line 34 def @error_message end |
#flag_key ⇒ String (readonly)
Returns The flag key that was evaluated.
28 29 30 |
# File 'lib/subflag/rails/evaluation_result.rb', line 28 def flag_key @flag_key end |
#reason ⇒ Symbol (readonly)
Returns The reason for this evaluation result Possible values: :default, :targeting_match, :static, :split, :error, :unknown.
25 26 27 |
# File 'lib/subflag/rails/evaluation_result.rb', line 25 def reason @reason end |
#value ⇒ Object (readonly)
Returns The resolved flag value.
18 19 20 |
# File 'lib/subflag/rails/evaluation_result.rb', line 18 def value @value end |
#variant ⇒ String? (readonly)
Returns The variant name that was selected.
21 22 23 |
# File 'lib/subflag/rails/evaluation_result.rb', line 21 def variant @variant end |
Class Method Details
.from_openfeature(details, flag_key:) ⇒ EvaluationResult
Build from OpenFeature evaluation details
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/subflag/rails/evaluation_result.rb', line 85 def self.from_openfeature(details, flag_key:) new( value: details[:value], variant: details[:variant], reason: details[:reason] || :unknown, flag_key: flag_key, error_code: details[:error_code], error_message: details[:error_message] ) end |
.from_subflag(result) ⇒ EvaluationResult
Build from Subflag::EvaluationResult (from Ruby provider)
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/subflag/rails/evaluation_result.rb', line 100 def self.from_subflag(result) # Convert uppercase reason string to lowercase symbol reason = result.reason&.downcase&.to_sym || :unknown new( value: result.value, variant: result.variant, reason: reason, flag_key: result.flag_key ) end |
Instance Method Details
#default? ⇒ Boolean
Check if the default value was returned
48 49 50 |
# File 'lib/subflag/rails/evaluation_result.rb', line 48 def default? reason == :default end |
#error? ⇒ Boolean
Check if there was an error during evaluation
55 56 57 |
# File 'lib/subflag/rails/evaluation_result.rb', line 55 def error? reason == :error || !error_code.nil? end |
#targeted? ⇒ Boolean
Check if the value came from targeting rules
62 63 64 |
# File 'lib/subflag/rails/evaluation_result.rb', line 62 def targeted? reason == :targeting_match end |
#to_h ⇒ Hash
Convert to hash representation
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/subflag/rails/evaluation_result.rb', line 69 def to_h { value: value, variant: variant, reason: reason, flag_key: flag_key, error_code: error_code, error_message: }.compact end |