Class: Unleash::FeatureToggle
- Inherits:
 - 
      Object
      
        
- Object
 - Unleash::FeatureToggle
 
 
- Defined in:
 - lib/unleash/feature_toggle.rb
 
Instance Attribute Summary collapse
- 
  
    
      #enabled  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute enabled.
 - 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute name.
 - 
  
    
      #strategies  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute strategies.
 - 
  
    
      #variant_definitions  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute variant_definitions.
 
Class Method Summary collapse
Instance Method Summary collapse
- #get_variant(context, fallback_variant = Unleash::FeatureToggle.disabled_variant) ⇒ Object
 - 
  
    
      #initialize(params = {})  ⇒ FeatureToggle 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of FeatureToggle.
 - #is_enabled?(context, default_result) ⇒ Boolean
 - #to_s ⇒ Object
 
Constructor Details
#initialize(params = {}) ⇒ FeatureToggle
Returns a new instance of FeatureToggle.
      12 13 14 15 16 17 18 19 20  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 12 def initialize(params = {}) params = {} if params.nil? self.name = params.fetch('name', nil) self.enabled = params.fetch('enabled', false) self.strategies = initialize_strategies(params) self.variant_definitions = initialize_variant_definitions(params) end  | 
  
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
      10 11 12  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 10 def enabled @enabled end  | 
  
#name ⇒ Object
Returns the value of attribute name.
      10 11 12  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 10 def name @name end  | 
  
#strategies ⇒ Object
Returns the value of attribute strategies.
      10 11 12  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 10 def strategies @strategies end  | 
  
#variant_definitions ⇒ Object
Returns the value of attribute variant_definitions.
      10 11 12  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 10 def variant_definitions @variant_definitions end  | 
  
Class Method Details
Instance Method Details
#get_variant(context, fallback_variant = Unleash::FeatureToggle.disabled_variant) ⇒ Object
      35 36 37 38 39 40 41 42 43 44 45 46 47  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 35 def get_variant(context, fallback_variant = Unleash::FeatureToggle.disabled_variant) raise ArgumentError, "Provided fallback_variant is not of type Unleash::Variant" if fallback_variant.class.name != 'Unleash::Variant' context = ensure_valid_context(context) return Unleash::FeatureToggle.disabled_variant unless self.enabled && am_enabled?(context, true) return Unleash::FeatureToggle.disabled_variant if sum_variant_defs_weights <= 0 variant = variant_from_override_match(context) || variant_from_weights(context, resolve_stickiness) Unleash.toggle_metrics.increment_variant(self.name, variant.name) unless Unleash.configuration.disable_metrics variant end  | 
  
#is_enabled?(context, default_result) ⇒ Boolean
      26 27 28 29 30 31 32 33  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 26 def is_enabled?(context, default_result) result = am_enabled?(context, default_result) choice = result ? :yes : :no Unleash.toggle_metrics.increment(name, choice) unless Unleash.configuration.disable_metrics result end  | 
  
#to_s ⇒ Object
      22 23 24  | 
    
      # File 'lib/unleash/feature_toggle.rb', line 22 def to_s "<FeatureToggle: name=#{name},enabled=#{enabled},strategies=#{strategies},variant_definitions=#{variant_definitions}>" end  |