diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-11-08 12:44:49 -0800 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-12-01 15:26:41 -0800 |
commit | 7c43692f68dd62773b0a7b094453f582a4242ef7 (patch) | |
tree | a6f1d3a99d73d0091f5918e91c36109379ab7765 /lib/gitlab | |
parent | 41412fec5b9aea8a6104320c5b554ffdabe52506 (diff) | |
download | gitlab-ce-7c43692f68dd62773b0a7b094453f582a4242ef7.tar.gz |
Make regexes more readable
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/background_migration/populate_untracked_uploads.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/gitlab/background_migration/populate_untracked_uploads.rb b/lib/gitlab/background_migration/populate_untracked_uploads.rb index ef0f1209ef5..42ad28400f4 100644 --- a/lib/gitlab/background_migration/populate_untracked_uploads.rb +++ b/lib/gitlab/background_migration/populate_untracked_uploads.rb @@ -5,7 +5,8 @@ module Gitlab self.table_name = 'unhashed_upload_files' # Ends with /:random_hex/:filename - FILE_UPLOADER_PATH_PATTERN = /\/\h+\/[^\/]+\z/ + FILE_UPLOADER_PATH_PATTERN = %r{/\h+/[^/]+\z} + FILE_UPLOADER_CAPTURE_FULL_PATH_PATTERN = %r{\A(.+)#{FILE_UPLOADER_PATH_PATTERN}} # These regex patterns are tested against a relative path, relative to # the upload directory. @@ -13,32 +14,32 @@ module Gitlab # it indicates the model_id. PATH_PATTERNS = [ { - pattern: /\A-\/system\/appearance\/logo\/(\d+)/, + pattern: %r{\A-/system/appearance/logo/(\d+)/}, uploader: 'AttachmentUploader', model_type: 'Appearance' }, { - pattern: /\A-\/system\/appearance\/header_logo\/(\d+)/, + pattern: %r{\A-/system/appearance/header_logo/(\d+)/}, uploader: 'AttachmentUploader', model_type: 'Appearance' }, { - pattern: /\A-\/system\/note\/attachment\/(\d+)/, + pattern: %r{\A-/system/note/attachment/(\d+)/}, uploader: 'AttachmentUploader', model_type: 'Note' }, { - pattern: /\A-\/system\/user\/avatar\/(\d+)/, + pattern: %r{\A-/system/user/avatar/(\d+)/}, uploader: 'AvatarUploader', model_type: 'User' }, { - pattern: /\A-\/system\/group\/avatar\/(\d+)/, + pattern: %r{\A-/system/group/avatar/(\d+)/}, uploader: 'AvatarUploader', model_type: 'Namespace' }, { - pattern: /\A-\/system\/project\/avatar\/(\d+)/, + pattern: %r{\A-/system/project/avatar/(\d+)/}, uploader: 'AvatarUploader', model_type: 'Project' }, @@ -90,7 +91,7 @@ module Gitlab if uploader == 'FileUploader' # Path relative to project directory in uploads matchd = path_relative_to_upload_dir.match(FILE_UPLOADER_PATH_PATTERN) - matchd[0].sub(/\A\//, '') # remove leading slash + matchd[0].sub(%r{\A/}, '') # remove leading slash else path_relative_to_carrierwave_root end @@ -120,7 +121,7 @@ module Gitlab # Not including a leading slash def path_relative_to_upload_dir - @path_relative_to_upload_dir ||= path.sub(/\A#{Gitlab::BackgroundMigration::PrepareUnhashedUploads::UPLOAD_DIR}\//, '') + @path_relative_to_upload_dir ||= path.sub(%r{\A#{Gitlab::BackgroundMigration::PrepareUnhashedUploads::UPLOAD_DIR}/}, '') end # Not including a leading slash @@ -141,8 +142,7 @@ module Gitlab end def file_uploader_model_id - pattern_to_capture_full_path = /\A(.+)#{FILE_UPLOADER_PATH_PATTERN}/ - matchd = path_relative_to_upload_dir.match(pattern_to_capture_full_path) + matchd = path_relative_to_upload_dir.match(FILE_UPLOADER_CAPTURE_FULL_PATH_PATTERN) raise "Could not capture project full_path from a FileUploader path: \"#{path_relative_to_upload_dir}\"" unless matchd full_path = matchd[1] project = Project.find_by_full_path(full_path) |