Class: UploadService

Inherits:
Object
  • Object
show all
Defined in:
app/services/upload_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, file, uploader_class = FileUploader, **uploader_context) ⇒ UploadService

Returns a new instance of UploadService.


4
5
6
# File 'app/services/upload_service.rb', line 4

def initialize(model, file, uploader_class = FileUploader, **uploader_context)
  @model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
end

Instance Method Details

#executeObject


8
9
10
11
12
13
14
15
# File 'app/services/upload_service.rb', line 8

def execute
  return unless @file && @file.size <= max_attachment_size

  uploader = @uploader_class.new(@model, nil, @uploader_context)
  uploader.store!(@file)

  uploader
end