Skip to content

Togglefy::FeatureQuery

The Togglefy::FeatureQuery class provides methods to query features based on various filters.

NameDescription
FILTERSMapping of filter keys to their corresponding query scopes.
Available keys: identifier, group/role, environment/env, tenant_id, status

Description


Get all features.

Usage


Togglefy.features

Return


ActiveRecord::Relation

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

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

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

Description


Get features that do not belong to any group.

Alias


without_role

Parameters


None

Usage Examples


Togglefy.without_group
Togglefy.without_role

Return


ActiveRecord::Relation

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

Description


Get features that do not belong to any environment.

Alias


without_env

Parameters


None

Usage Examples


Togglefy.without_environment
Togglefy.without_env

Return


ActiveRecord::Relation

Description


Get features of a specific tenant.

Parameters


tenant_id: String

Usage Examples


Togglefy.for_tenant("123abc456def789ghi0")

Return


ActiveRecord::Relation

Description


Get features that do not belong to any tenant.

Parameters


None

Usage Examples


Togglefy.without_tenant

Return


ActiveRecord::Relation

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

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