Class: Determinator::Feature
- Inherits:
-
Object
- Object
- Determinator::Feature
- Defined in:
- lib/determinator/feature.rb
Overview
A model for an individual feature or experiment
Constant Summary collapse
- BUCKET_TYPES =
%i(id guid fallback)
Instance Attribute Summary collapse
-
#bucket_type ⇒ Object
readonly
Returns the value of attribute bucket_type.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#target_groups ⇒ Object
readonly
Returns the value of attribute target_groups.
-
#variants ⇒ nil, Hash<String,Integer>
readonly
The variants for this experiment, with the name of the variant as the key and the weight as the value.
Instance Method Summary collapse
-
#experiment? ⇒ true, false
Is this feature an experiment?.
-
#feature_flag? ⇒ true, false
Is this feature a feature flag?.
-
#initialize(name:, identifier:, bucket_type:, target_groups:, variants: {}, overrides: {}) ⇒ Feature
constructor
A new instance of Feature.
-
#overridden_for?(id) ⇒ true, false
Is this feature overridden for the given actor id?.
- #override_value_for(id) ⇒ Object
Constructor Details
#initialize(name:, identifier:, bucket_type:, target_groups:, variants: {}, overrides: {}) ⇒ Feature
Returns a new instance of Feature.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/determinator/feature.rb', line 10 def initialize(name:, identifier:, bucket_type:, target_groups:, variants: {}, overrides: {}) @name = name.to_s @identifier = identifier.to_s @variants = variants @target_groups = target_groups @bucket_type = bucket_type.to_sym raise ArgumentError, "Unknown bucket type: #{bucket_type}" unless BUCKET_TYPES.include?(@bucket_type) # To prevent confusion between actor id data types @overrides = Hash[overrides.map { |k, v| [k.to_s, v] }] end |
Instance Attribute Details
#bucket_type ⇒ Object (readonly)
Returns the value of attribute bucket_type.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def bucket_type @bucket_type end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def name @name end |
#target_groups ⇒ Object (readonly)
Returns the value of attribute target_groups.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def target_groups @target_groups end |
#variants ⇒ nil, Hash<String,Integer> (readonly)
The variants for this experiment, with the name of the variant as the key and the weight as the value. Will be nil for non-experiments.
5 6 7 |
# File 'lib/determinator/feature.rb', line 5 def variants @variants end |
Instance Method Details
#experiment? ⇒ true, false
24 25 26 |
# File 'lib/determinator/feature.rb', line 24 def experiment? variants.any? end |
#feature_flag? ⇒ true, false
29 30 31 |
# File 'lib/determinator/feature.rb', line 29 def feature_flag? variants.empty? end |
#overridden_for?(id) ⇒ true, false
Is this feature overridden for the given actor id?
36 37 38 |
# File 'lib/determinator/feature.rb', line 36 def overridden_for?(id) overrides.has_key?(id.to_s) end |
#override_value_for(id) ⇒ Object
40 41 42 |
# File 'lib/determinator/feature.rb', line 40 def override_value_for(id) overrides[id.to_s] end |