Class: Togls::Rules::Group
- Inherits:
-
Togls::Rule
- Object
- Togls::Rule
- Togls::Rules::Group
- Defined in:
- lib/togls/rules/group.rb
Overview
Group Rule
The Group Rule is a provided Rule that expects to be given an Array as it’s initialization data and when evaluated determines the toggle state based on the given target being included in the Array that was passed in during initialization. This allows you to define various groups. For example:
alpha_testers = Togls::Rules::Group.new([‘[email protected]’, ‘[email protected]’]) Togls.features do
feature(:foo).on(alpha_testers)
end
if Togls.feature(:foo).on?(current_user.email)
...
end
Instance Attribute Summary
Attributes inherited from Togls::Rule
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Togls::Rule
#initialize, #missing_target_type?, target_type, #target_type
Constructor Details
This class inherits a constructor from Togls::Rule
Class Method Details
.description ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/togls/rules/group.rb', line 24 def self.description %Q{ The Group rule allows you to define an arbitrary collection of objects to be used in evaluating against the target. Specify the initialization data as an array of inclusive identifiers for the group. When the feature toggle is evaluated if the passed in target is included in the group then it is evaluated to on. If not, it evaluates to off. Examples: # Group defined by user ids alpha_testers = Togls::Rules::Group.new([23, 343, 222, 123]) # Group defined by email addresses beta_testers = Togls::Rules::Group.new(['[email protected]', '[email protected]']) Togls.release do feature(:foo, 'some foo desc').on(beta_testers) end Togls.feature(:foo).on?('[email protected]') # evalutes to false (a.k.a. off) } end |
.title ⇒ Object
20 21 22 |
# File 'lib/togls/rules/group.rb', line 20 def self.title "Group" end |
Instance Method Details
#run(_key, target) ⇒ Object
46 47 48 |
# File 'lib/togls/rules/group.rb', line 46 def run(_key, target) @data.include?(target) end |