Togglefy::FeatureQuery
The Togglefy::FeatureQuery
class provides methods to query features based on various filters.
Constants
Section titled “Constants”Name | Description |
---|---|
FILTERS | Mapping of filter keys to their corresponding query scopes. Available keys: identifier , group /role , environment /env , tenant_id , status |
Methods
Section titled “Methods”features
Section titled “features”Description
Get all features.
Usage
Togglefy.features
Return
ActiveRecord::Relation
feature
Section titled “feature”Description
Find feature(s) by identifier.
Parameters
identifier: Symbol || String || Array(String || Symbol)
Usage Examples
Togglefy.feature(:feature_name)Togglefy.feature("feature_name")Togglefy.feature([ :feature_name_1, "feature_name_2" ])
Return
Togglefy::Feature || ActiveRecord::Relation
for_type
Section titled “for_type”Description
Get feature assignments for an Assignable type.
Parameters
klass: Class
Usage Examples
Togglefy.for_type(User) # This returns all FeatureAssignment with a User assignable
Return
ActiveRecord::Relation
for_group
Section titled “for_group”Description
Get features of a specific group.
Alias
for_role
Parameters
group: Symbol || String
Usage Examples
Togglefy.for_group(:admin)Togglefy.for_role(:admin)
Return
ActiveRecord::Relation
without_group
Section titled “without_group”Description
Get features that do not belong to any group.
Alias
without_role
Parameters
None
Usage Examples
Togglefy.without_groupTogglefy.without_role
Return
ActiveRecord::Relation
for_environment
Section titled “for_environment”Description
Get features of a specific environment.
Alias
for_env
Parameters
environment: Symbol || String
Usage Examples
Togglefy.for_environment(:production)Togglefy.for_env(:production)
Return
ActiveRecord::Relation
without_environment
Section titled “without_environment”Description
Get features that do not belong to any environment.
Alias
without_env
Parameters
None
Usage Examples
Togglefy.without_environmentTogglefy.without_env
Return
ActiveRecord::Relation
for_tenant
Section titled “for_tenant”Description
Get features of a specific tenant.
Parameters
tenant_id: String
Usage Examples
Togglefy.for_tenant("123abc456def789ghi0")
Return
ActiveRecord::Relation
without_tenant
Section titled “without_tenant”Description
Get features that do not belong to any tenant.
Parameters
None
Usage Examples
Togglefy.without_tenant
Return
ActiveRecord::Relation
with_status
Section titled “with_status”Description
Get features with a specific status.
Parameters
status: Symbol || String || Integer
Usage Examples
Togglefy.with_status(:active)Togglefy.with_status("inactive")Togglefy.with_status(1)
Return
ActiveRecord::Relation
for_filters
Section titled “for_filters”Description
Apply multiple filters to the query features.
Parameters
Despite the types informed, you can also pass nil
to filter for features that do not have anything set.
filters: { group: Symbol || String || nil, role: Symbol || String || nil, # Acts as a group environment: Symbol || String || nil, env: Symbol || String || nil, # Acts as environment tenant_id: String || nil, status: Symbol || String || Integer || nil, identifier: Symbol || String || Array(String || Symbol) || nil}
Usage Examples
Togglefy.for_filters( filters: { group: :admin, environment: :production, status: :active })
Return
ActiveRecord::Relation