Move `prepend` calls outside of classes to the last line in the file
In https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8153/ and https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8047 we moved the prepend
line of the affected models to the last line, outside of the class
block. This was necessary to ensure all code was defined that the prepended modules may want to override, as otherwise various specs would fail.
This approach has two main benefits:
- When we prepend the module, the target class has been fully defined, instead of only partially. This means we don't have to place the
prepend
in a specific place if we want to depend on say constants in the class. - It reduces the chance of merge conflicts, because the
prepend
now comes after all the CE code
This was discussed in https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8153#note_113239380, and I believe we should start applying this to all existing cases to ensure the codebase is consistently using this pattern.
TODO
-
app/controllers
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8201 -
app/finders
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8192 -
app/mailers
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8202 -
app/models
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8198 -
app/policies
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8204 -
app/presenters
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8205 -
app/services
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8200 -
app/workers
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8206 -
app/helpers
: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8422 -
Remainder: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8424
To do this, you can use the following script: https://gitlab.com/gitlab-org/release/framework/snippets/1773219
To use:
- Change
Dir['app/models/**/*.rb'].each do |path|
to use the appropriate path (e.g.app/services/**/*.rb
) - Run it using
ruby move_prepend.rb
in the EE source directory
Edited by Yorick Peterse