Provided Rules Reference
The following is a list of all of the provided rules, their explanations, and some examples of how they can be used.
This is the simplest of the provided rules. It simply takes a boolean
during construction and returns that boolean value when
run is called
on it. Example:
rule = Togls.rule(:my_rule, :boolean, true) rule.run(:some_feature_key) # => true
This rule is intended to allow feature toggles to be able to be controlled based on someone or something existing/not existing within a group. For example this could be used to enable a feature for a specified list of email addresses.
# Create a group rule togls_devs = Togls.rule(:togls_devs, :group, ["firstname.lastname@example.org", "email@example.com", "firstname.lastname@example.org"], :user_email_address) # defining the feature toggles Togls.release do feature(:new_contact_form, "use new contact form instead of old one", :user_email_address).on(togls_devs) end # evaluating the feature toggles if Togls.feature(:new_contact_form).on?("email@example.com") # Use new contact form else # Use old contact form end
In the above snippet the
:new_contact_form feature toggle is on/off
conditionally based on if "firstname.lastname@example.org" is in the group
("email@example.com", "firstname.lastname@example.org", "email@example.com").
In this particular case "firstname.lastname@example.org" is not. Therefore,
would come back with a value of false and we would end up in
# Use old contact form code branch.
Prior to v3.0.0 both these rules existed but their construction was as follows because the concepts of rule ids, rule types and target types didn't exist before v3.0.0.
rule = Togls::Rules::Boolean.new(true) togls_devs = Togls::Rules::Group.new(["email@example.com", "firstname.lastname@example.org", "email@example.com"])