-
Notifications
You must be signed in to change notification settings - Fork 0
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, ["brimil01@gmail.com", "cyphactor@gmail.com", "ryanhedges@gmail.com"], :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?("user@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 "user@example.com" is in the group
("brimil01@gmail.com", "cyphactor@gmail.com", "ryanhedges@gmail.com").
In this particular case "user@example.com" is not. Therefore, on?
would come back with a value of false and we would end up in
the # 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(["brimil01@gmail.com", "cyphactor@gmail.com", "ryanhedges@gmail.com"])