gitlab-org--gitlab-foss/app/services/upload_service.rb
Heinrich Lee Yu 63e9969ca3 Refactor upload service to return uploader
Also changes old calls to the service
2019-01-07 11:16:58 +08:00

22 lines
546 B
Ruby

# frozen_string_literal: true
class UploadService
def initialize(model, file, uploader_class = FileUploader, **uploader_context)
@model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
end
def execute
return nil unless @file && @file.size <= max_attachment_size
uploader = @uploader_class.new(@model, nil, @uploader_context)
uploader.store!(@file)
uploader
end
private
def max_attachment_size
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
end
end