Feature object Featury
A feature object can contain work with either one specific feature flag or several feature flags. Several feature flags can also be represented as a group — a nested feature object.
Prefix
A feature object always has a prefix. By default, it is built based on the class name of the feature object. For example, for User::OnboardingFeature
the default prefix will be user_onboarding
.
You can change the prefix using the prefix
method:
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
# ...
end
Resources
A feature object may expect a resource to be passed to it as input. These resources can be used in actions as an addition to working with feature flags.
Options
Option option
Makes the resource optional for calling the feature object. Defaults to false
.
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User, option: true
# ...
end
Option nested
Passes a resource to nested feature objects via groups
. Defaults to false
.
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User, nested: true
# ...
end
Condition
A feature object can contain a basic condition for operation. For example, this can be useful if you want to allow work with a resource only in a certain state.
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User
condition ->(resources:) { resources.user.onboarding_awaiting? }
# ...
end
Set of features
Within a single feature object, you can specify one feature flag or several feature flags.
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User
condition ->(resources:) { resources.user.onboarding_awaiting? }
features :passage
end
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User
condition ->(resources:) { resources.user.onboarding_awaiting? }
features :passage, :integration
end
Together with the onboarding
prefix, an example of which is presented above, these feature flags will be collected:
# => onboarding_passage
# => onboarding_passage
# => onboarding_integration
Groups of feature sets
class User::OnboardingFeature < ApplicationFeature
prefix :onboarding
resource :user, type: User
condition ->(resources:) { resources.user.onboarding_awaiting? }
features :passage
groups BillingFeature,
PaymentSystemFeature
end