Draft: Feature flag class macros
What does this MR do and why?
Feature flags are used to fork code paths during runtime. Rails provides class macros like has_one
, validate
, scope
that are evaluated during class setup. There are cases where we want to feature flag changes to these calls. The below code won't work, but illustrates the direction we want to go:
class User
if Feature.enabled?(:the_feature_flag)
has_one :namespace, required: true
else
has_one :namespace, required: false
end
end
The Feature.enabled?
will only be run during construction of the User
class. We want Feature.enabled?
to execute at runtime and switch between a required: true
and required: false
relationship.
This MR provides:
- A generic ability to extend class macros.
- A specialized ability to extend association class macros that builds on (1).
This MR is required as the next step in making user personal namespaces optional.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #427730