Class: Determinator::Feature
- Inherits:
-
Object
- Object
- Determinator::Feature
- Defined in:
- lib/determinator/feature.rb
Overview
A model for an individual feature or experiment
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#bucket_type ⇒ Object
readonly
Returns the value of attribute bucket_type.
-
#fixed_determinations ⇒ Object
readonly
Returns the value of attribute fixed_determinations.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#structured_bucket ⇒ Object
readonly
Returns the value of attribute structured_bucket.
-
#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.
-
#winning_variant ⇒ Object
readonly
Returns the value of attribute winning_variant.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #active? ⇒ Boolean
-
#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:, structured_bucket: nil, fixed_determinations: [], variants: {}, overrides: {}, active: false, winning_variant: nil) ⇒ 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
-
#parse_outcome(outcome, allow_exclusion:) ⇒ Object
Validates the given outcome for this feature.
-
#structured? ⇒ true, false
Is this feature using structured identification?.
- #to_explain_params ⇒ Object
Constructor Details
#initialize(name:, identifier:, bucket_type:, target_groups:, structured_bucket: nil, fixed_determinations: [], variants: {}, overrides: {}, active: false, winning_variant: nil) ⇒ Feature
Returns a new instance of Feature.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/determinator/feature.rb', line 8 def initialize(name:, identifier:, bucket_type:, target_groups:, structured_bucket: nil, fixed_determinations: [], variants: {}, overrides: {}, active: false, winning_variant: nil) @name = name.to_s @identifier = identifier.to_s @variants = variants @target_groups = parse_target_groups(target_groups) @fixed_determinations = parse_fixed_determinations(fixed_determinations) @winning_variant = parse_outcome(winning_variant, allow_exclusion: false) @active = active @bucket_type = bucket_type.to_sym @structured_bucket = structured_bucket # To prevent confusion between actor id data types @overrides = overrides.each_with_object({}) do |(identifier, outcome), hash| parsed = parse_outcome(outcome, allow_exclusion: true) hash[identifier.to_s] = parsed unless parsed.nil? end end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def active @active end |
#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 |
#fixed_determinations ⇒ Object (readonly)
Returns the value of attribute fixed_determinations.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def fixed_determinations @fixed_determinations 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 |
#structured_bucket ⇒ Object (readonly)
Returns the value of attribute structured_bucket.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def structured_bucket @structured_bucket 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 |
#winning_variant ⇒ Object (readonly)
Returns the value of attribute winning_variant.
6 7 8 |
# File 'lib/determinator/feature.rb', line 6 def winning_variant @winning_variant end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 |
# File 'lib/determinator/feature.rb', line 63 def ==(other) Marshal.dump(self) == Marshal.dump(other) end |
#active? ⇒ Boolean
26 27 28 |
# File 'lib/determinator/feature.rb', line 26 def active? !!active end |
#experiment? ⇒ true, false
Returns Is this feature an experiment?.
31 32 33 |
# File 'lib/determinator/feature.rb', line 31 def experiment? variants.any? end |
#feature_flag? ⇒ true, false
Returns Is this feature a feature flag?.
36 37 38 |
# File 'lib/determinator/feature.rb', line 36 def feature_flag? variants.empty? end |
#overridden_for?(id) ⇒ true, false
Is this feature overridden for the given actor id?
48 49 50 |
# File 'lib/determinator/feature.rb', line 48 def overridden_for?(id) overrides.has_key?(id.to_s) end |
#override_value_for(id) ⇒ Object
52 53 54 |
# File 'lib/determinator/feature.rb', line 52 def override_value_for(id) overrides[id.to_s] end |
#parse_outcome(outcome, allow_exclusion:) ⇒ Object
Validates the given outcome for this feature.
57 58 59 60 61 |
# File 'lib/determinator/feature.rb', line 57 def parse_outcome(outcome, allow_exclusion:) valid_outcomes = experiment? ? variants.keys : [true] valid_outcomes << false if allow_exclusion valid_outcomes.include?(outcome) ? outcome : nil end |
#structured? ⇒ true, false
Returns Is this feature using structured identification?.
41 42 43 |
# File 'lib/determinator/feature.rb', line 41 def structured? !!structured_bucket && !structured_bucket.empty? end |
#to_explain_params ⇒ Object
67 68 69 |
# File 'lib/determinator/feature.rb', line 67 def to_explain_params { name: name, identifier: identifier, bucket_type: bucket_type } end |