Skip to content

Draft: Feature flag class macros

Alex Pooley requested to merge 427730-class-macro-with-ff into master

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:

  1. A generic ability to extend class macros.
  2. 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.

Related to #427730

Edited by Alex Pooley

Merge request reports