toggly 0.6.0 → 1.0.0

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.
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Toggly
4
- # Server-evaluated variant entry for a single feature flag, as returned by
5
- # `evaluated-variants-signed`. This is distinct from `FeatureDefinition`
6
- # (client-side rules): the server has already picked the winning variant.
7
- class EvaluatedVariantDef
8
- # @return [Boolean] Whether the feature is enabled for this assignment
9
- attr_reader :enabled
10
-
11
- # @return [String, nil] Assigned variant name, if any
12
- attr_reader :variant
13
-
14
- # @return [Object, nil] Configuration payload for the variant (shape depends on the feature)
15
- attr_reader :configuration_value
16
-
17
- def initialize(enabled:, variant: nil, configuration_value: nil)
18
- @enabled = enabled ? true : false
19
- @variant = variant
20
- @configuration_value = configuration_value
21
- end
22
-
23
- # Create from a hash (API response or snapshot; camelCase or snake_case).
24
- #
25
- # @param hash [Hash]
26
- # @return [EvaluatedVariantDef]
27
- def self.from_hash(hash)
28
- hash = symbolize_keys(hash)
29
- configuration_value = if hash.key?(:configurationValue)
30
- hash[:configurationValue]
31
- else
32
- hash[:configuration_value]
33
- end
34
-
35
- new(
36
- enabled: hash[:enabled],
37
- variant: hash[:variant],
38
- configuration_value: configuration_value
39
- )
40
- end
41
-
42
- # Convert to a hash for serialization (snapshot persistence).
43
- #
44
- # @return [Hash]
45
- def to_h
46
- {
47
- enabled: @enabled,
48
- variant: @variant,
49
- configuration_value: @configuration_value
50
- }
51
- end
52
-
53
- def ==(other)
54
- other.is_a?(EvaluatedVariantDef) &&
55
- @enabled == other.enabled &&
56
- @variant == other.variant &&
57
- @configuration_value == other.configuration_value
58
- end
59
- alias eql? ==
60
-
61
- def self.symbolize_keys(hash)
62
- return hash unless hash.is_a?(Hash)
63
-
64
- hash.transform_keys { |k| k.is_a?(String) ? k.to_sym : k }
65
- end
66
- private_class_method :symbolize_keys
67
- end
68
-
69
- # Assigned variant name and configuration value for a feature, returned by
70
- # `Client#get_variant` when `Config#enable_variants` is true.
71
- class VariantResult
72
- # @return [String] Variant name assigned by the server
73
- attr_reader :name
74
-
75
- # @return [Object, nil] Optional configuration payload for the variant
76
- attr_reader :configuration_value
77
-
78
- def initialize(name:, configuration_value: nil)
79
- @name = name
80
- @configuration_value = configuration_value
81
- end
82
-
83
- # @return [Hash]
84
- def to_h
85
- { name: @name, configuration_value: @configuration_value }
86
- end
87
- end
88
- end