Skip to content

Managing Features

To manage Togglefy::Feature is the art of create, update, destroy, toggle Features.

To create features it’s as simple as drinking a nice cold beer after a hard day or drinking the entire bottle of coffee in a span of 1 hour:

Togglefy::Feature.create(
name: "Magic",
description: "You're a Wizard, Harry"
) # To create a simple Feature

If you have tenant, groups (or roles), difference between environments, you can do the following:

Togglefy::Feature.create(
name: "Super Powers",
description: "With great power comes great responsibility",
tenant_id: "123abc",
group: :admin,
environment: :production
)

You can also use:

Togglefy.create(
name: "Teleportation",
description: "Allows the assignable to teleport to anywhere",
group: :jumper
)
# Or
Togglefy.create_feature(
name: "Teleportation",
description: "Allows the assignable to teleport to anywhere",
group: :jumper
)

Whenever you create a Togglefy::Feature, you can expect something like this:

{
id: 1,
name: "Super Powers",
identifier: "super_powers",
description: "With great power comes great responsibility",
created_at: "2025-04-12 01:39:10.176561000 +0000",
updated_at: "2025-04-12 01:39:46.818928000 +0000",
tenant_id: "123abc",
group: "admin",
environment: "production",
status: "inactive"
}

To update a feature is as simple as riding on a monocycle while balancing a cup of water on the top of a really tall person that’s on your shoulders.

Here’s how you can do it:

Togglefy.update(:super_powers, tenant_id: "abc123")
Togglefy.update_feature(:super_powers, tenant_id: "abc123")

Or by finding the feature manually and then updating it like you always do with Rails:

feature = Togglefy::Feature.find_by(identifier: :super_powers)
# or
feature = Togglefy.feature(:super_powers) # This is explained more in the "Finding a specific feature" section of this README
feature.update(tenant_id: "123abc")

It looks like you’re mean 😈. Do you want to cause destruction?

Well… we, the contributors, have nothing to do with this, so here’s how you can destroy a feature:

Togglefy.destroy(:super_powers)
Togglefy.destroy_feature(:super_powers)
Togglefy::Feature.identifier(:super_powers).destroy
Togglefy::Feature.find_by(identifier: :super_powers).destroy

You can toggle a feature status between active and inactive by doing this:

Togglefy.toggle(:super_powers)
Togglefy.toggle_feature(:super_powers)

As you can see, the Togglefy::Feature also has a status and it is default to inactive. You can change this during creation.

The status of a Togglefy::Feature should not be interpreted as if the Assignable has the feature.

The status holds the inactive or active values. This status is not to define if an Assignable (any model that has the include Togglefy::Assignable) either has or doesn’t have a feature, but to decide if this feature is available system/application-wide.

It’s up to you to define how you will implement it:

  • Is it inactive? Then this feature is likely unreleased
  • Or maybe if it is inactive, it means that the feature is unavailable for some reason? Maintenance?

Again, it’s up to you!

The status can be:

:inactive || "inactive" || 0
:active || "active" || 1

You can change the status by:

  • Sending a value during creation
  • Updating the column
  • Doing a:
    Togglefy::Feature.find_by(identifier: :super_powers).active!
    Togglefy.feature(:super_powers).active!
    Togglefy.active!(:super_powers)
    Togglefy.activate_feature(:super_powers)
    Togglefy::Feature.find_by(identifier: :super_powers).inactive!
    Togglefy.feature(:super_powers).inactive!
    Togglefy.inactive!(:super_powers)
    Togglefy.inactivate_feature(:super_powers)