Allow Safeguards to be added and/or overridden outside of core #720
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allow consumers to define their own safeguards and maintain existing behavior for backwards compatibility.
Safeguard
to use a registrySimilar to how RuboCop handles Cops from itself, gems, plugins, and local repos.
Safeguard.run
executes each registered safeguard.Safeguard::Base
classConsumers can create new safeguards by inheriting this class. Safeguards are added to the registry through
inherited
.Safeguard::Deprecated
classJust a marker for the existing core-defined safeguards. The idea is that these would eventually get deleted after the adapters are updated to implement their own.
If a safeguard is registered by the same name as a deprecated safeguard it will be executed instead.
This will allow the resolution issues like #659 and #684 by enabling adapters (or users) to define their own safeguards.
For example, to resolve #684
database_cleaner-active_record
can implement its ownAllowedUrl
to override the existing behavior.Simplified example: