Module: Togglefy
- Defined in:
- lib/togglefy.rb,
lib/togglefy/engine.rb,
lib/togglefy/errors.rb,
lib/togglefy/version.rb,
lib/togglefy/assignable.rb,
lib/togglefy/featureable.rb,
lib/togglefy/errors/error.rb,
lib/togglefy/feature_query.rb,
app/models/togglefy/feature.rb,
lib/togglefy/feature_manager.rb,
lib/togglefy/scoped_bulk_wrapper.rb,
lib/togglefy/services/bulk_toggler.rb,
lib/togglefy/errors/feature_not_found.rb,
app/models/togglefy/feature_assignment.rb,
lib/togglefy/errors/bulk_toggle_failed.rb,
lib/togglefy/errors/dependency_missing.rb,
lib/togglefy/feature_assignable_manager.rb,
lib/generators/togglefy/install_generator.rb,
lib/togglefy/errors/assignables_not_found.rb,
lib/togglefy/errors/invalid_feature_attribute.rb
Overview
The Togglefy module provides a feature management system. It includes methods for querying, creating, updating, toggling, and managing features. It also provides a way to manage features for assignable objects.
Features
The Togglefy module provides a variety of features, including:
-
Querying features by type, group, environment, tenant, and custom filters
-
Creating, updating, and deleting features
-
Managing features for Assignables
For more detailed information on each method, please refer to the README, individual method documentation in this file or the usage documentation.
Usage
Main usage for this always starts with the Togglefy module.
Below are a few examples on how to use Togglefy:
Examples
-
Togglefy.feature(:super_powers)
-
Togglefy.for_type(User)
-
Togglefy.for_group(group)
-
Togglefy.for_filters(filters: {group: :admin})
-
Togglefy.with_status(:active)
-
Togglefy.create(name: “Feature Name”, identifier: :feature_name, description: “Feature description”)
-
Togglefy.update(:feature_name, name: “Updated Feature Name”)
-
Togglefy.destroy(:feature_name)
-
Togglefy.toggle(:feature_name)
-
Togglefy.inactive!(:feature_name)
-
Togglefy.for(assignable).enable(:feature_name)
-
Togglefy.for(assignable).has?(:feature_name)
-
Togglefy.mass_for(Assignable).bulk.enable(:feature_name)
-
Togglefy.mass_for(Assignable).bulk.enable(:feature_name, percentage: 35)
-
Togglefy.mass_for(Assignable).bulk.disable([:feature_name, :another_feature])
Aliases
The following aliases are available for convenience:
-
for_roleis an alias forfor_group -
without_roleis an alias forwithout_group -
for_envis an alias forfor_environment -
without_envis an alias forwithout_environment -
create_featureis an alias forcreate -
update_featureis an alias forupdate -
toggle_featureis an alias fortoggle -
activate_featureis an alias foractive! -
inactivate_featureis an alias forinactive! -
destroy_featureis an alias fordestroy
Defined Under Namespace
Modules: Assignable, Generators Classes: AssignablesNotFound, BulkToggleFailed, BulkToggler, DependencyMissing, Engine, Error, Feature, FeatureAssignableManager, FeatureAssignment, FeatureManager, FeatureNotFound, FeatureQuery, InvalidFeatureAttribute, ScopedBulkWrapper
Constant Summary collapse
- StandardError =
Overwrites the default StandardError class to provide a custom error class for Togglefy.
Class.new(Error)
- VERSION =
The VERSION constant defines the current version of the Togglefy gem.
"1.2.1"- Featureable =
Deprecated.
Use
Togglefy::Assignableinstead.Featureableis an alias forAssignable. Assignable
Class Method Summary collapse
-
.active!(identifier) ⇒ boolean
(also: activate_feature)
Activates a feature.
-
.create(**params) ⇒ Feature
(also: create_feature)
Creates a new feature.
-
.destroy(identifier) ⇒ boolean
(also: destroy_feature)
Deletes a feature.
-
.feature(identifier) ⇒ Feature
Finds a feature by its identifier.
-
.features ⇒ Array
Returns all features.
-
.for(assignable) ⇒ FeatureAssignableManager
Manages features for a specific assignable object.
-
.for_environment(environment) ⇒ Array
(also: for_env)
Queries features for a specific environment.
-
.for_filters(filters: {}) ⇒ Array
Queries features based on custom filters.
-
.for_group(group) ⇒ Array
(also: for_role)
Queries features for a specific group.
-
.for_tenant(tenant_id) ⇒ Array
Queries features for a specific tenant.
-
.for_type(klass) ⇒ Array
Queries features for a specific type.
-
.inactive!(identifier) ⇒ boolean
(also: inactivate_feature)
Deactivates a feature.
-
.mass_for(klass) ⇒ ScopedBulkWrapper
Provides bulk management for a specific class.
-
.toggle(identifier) ⇒ boolean
(also: toggle_feature)
Toggles the status of a feature.
-
.update(identifier, **params) ⇒ Feature
(also: update_feature)
Updates an existing feature.
-
.with_status(status) ⇒ Array
Queries features by their status.
-
.without_environment ⇒ Array
(also: without_env)
Queries features without an environment.
-
.without_group ⇒ Array
(also: without_role)
Queries features without a group.
-
.without_tenant ⇒ Array
Queries features without a tenant.
Class Method Details
.active!(identifier) ⇒ boolean Also known as: activate_feature
Activates a feature.
210 211 212 213 214 |
# File 'lib/togglefy.rb', line 210 def self.active!(identifier) FeatureManager.new(identifier).active! rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.create(**params) ⇒ Feature Also known as: create_feature
All parameters are optional, except for the name. If sent, it should be a keyword argument.
Creates a new feature.
159 160 161 |
# File 'lib/togglefy.rb', line 159 def self.create(**params) FeatureManager.new.create(**params) end |
.destroy(identifier) ⇒ boolean Also known as: destroy_feature
Deletes a feature.
190 191 192 193 194 |
# File 'lib/togglefy.rb', line 190 def self.destroy(identifier) FeatureManager.new(identifier).destroy rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.feature(identifier) ⇒ Feature
Finds a feature by its identifier.
78 79 80 81 82 |
# File 'lib/togglefy.rb', line 78 def self.feature(identifier) FeatureQuery.new.feature(identifier) rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.features ⇒ Array
Returns all features.
70 71 72 |
# File 'lib/togglefy.rb', line 70 def self.features FeatureQuery.new.features end |
.for(assignable) ⇒ FeatureAssignableManager
Manages features for a specific assignable object.
229 230 231 |
# File 'lib/togglefy.rb', line 229 def self.for(assignable) FeatureAssignableManager.new(assignable) end |
.for_environment(environment) ⇒ Array Also known as: for_env
Queries features for a specific environment.
107 108 109 |
# File 'lib/togglefy.rb', line 107 def self.for_environment(environment) FeatureQuery.new.for_environment(environment) end |
.for_filters(filters: {}) ⇒ Array
Queries features based on custom filters.
133 134 135 |
# File 'lib/togglefy.rb', line 133 def self.for_filters(filters: {}) FeatureQuery.new.for_filters(filters) end |
.for_group(group) ⇒ Array Also known as: for_role
Queries features for a specific group.
94 95 96 |
# File 'lib/togglefy.rb', line 94 def self.for_group(group) FeatureQuery.new.for_group(group) end |
.for_tenant(tenant_id) ⇒ Array
Queries features for a specific tenant.
120 121 122 |
# File 'lib/togglefy.rb', line 120 def self.for_tenant(tenant_id) FeatureQuery.new.for_tenant(tenant_id) end |
.for_type(klass) ⇒ Array
Queries features for a specific type.
87 88 89 |
# File 'lib/togglefy.rb', line 87 def self.for_type(klass) FeatureQuery.new.for_type(klass) end |
.inactive!(identifier) ⇒ boolean Also known as: inactivate_feature
Deactivates a feature.
220 221 222 223 224 |
# File 'lib/togglefy.rb', line 220 def self.inactive!(identifier) FeatureManager.new(identifier).inactive! rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.mass_for(klass) ⇒ ScopedBulkWrapper
Provides bulk management for a specific class.
236 237 238 |
# File 'lib/togglefy.rb', line 236 def self.mass_for(klass) Togglefy::ScopedBulkWrapper.new(klass) end |
.toggle(identifier) ⇒ boolean Also known as: toggle_feature
Toggles the status of a feature.
200 201 202 203 204 |
# File 'lib/togglefy.rb', line 200 def self.toggle(identifier) FeatureManager.new(identifier).toggle rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.update(identifier, **params) ⇒ Feature Also known as: update_feature
All parameters but the first (identifier) should be keyword arguments.
Updates an existing feature.
180 181 182 183 184 |
# File 'lib/togglefy.rb', line 180 def self.update(identifier, **params) FeatureManager.new(identifier).update(**params) rescue ActiveRecord::RecordNotFound raise Togglefy::FeatureNotFound, "Couldn't find Togglefy::Feature with identifier '#{identifier}'" end |
.with_status(status) ⇒ Array
Queries features by their status.
140 141 142 |
# File 'lib/togglefy.rb', line 140 def self.with_status(status) FeatureQuery.new.with_status(status) end |
.without_environment ⇒ Array Also known as: without_env
Queries features without an environment.
113 114 115 |
# File 'lib/togglefy.rb', line 113 def self.without_environment FeatureQuery.new.without_environment end |
.without_group ⇒ Array Also known as: without_role
Queries features without a group.
100 101 102 |
# File 'lib/togglefy.rb', line 100 def self.without_group FeatureQuery.new.without_group end |
.without_tenant ⇒ Array
Queries features without a tenant.
126 127 128 |
# File 'lib/togglefy.rb', line 126 def self.without_tenant FeatureQuery.new.without_tenant end |