gitlab-org--gitlab-foss/app/services/upload_service.rb
Andrew Newdigate 3288e1a874 Adds the Rubocop ReturnNil cop
This style change enforces `return if ...` instead of
`return nil if ...` to save maintainers a few minor review points
2019-03-06 17:51:56 +02:00

22 lines
542 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 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