Skip to content

Provided Rules Reference

Andrew De Ponte edited this page Jun 30, 2016 · 6 revisions

The following is a list of all of the provided rules, their explanations, and some examples of how they can be used.

Togls::Rules::Boolean

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

Togls::Rules::Group

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.

Older Versions

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"])
You can’t perform that action at this time.