Class: Packages::UpdatePackageFileService
- Inherits:
-
Object
- Object
- Packages::UpdatePackageFileService
- Defined in:
- app/services/packages/update_package_file_service.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(package_file, params) ⇒ UpdatePackageFileService
constructor
A new instance of UpdatePackageFileService.
Constructor Details
#initialize(package_file, params) ⇒ UpdatePackageFileService
Returns a new instance of UpdatePackageFileService.
7 8 9 10 |
# File 'app/services/packages/update_package_file_service.rb', line 7 def initialize(package_file, params) @package_file = package_file @params = params end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/packages/update_package_file_service.rb', line 12 def execute check_params return if same_as_params? # we need to access the file *before* updating the attributes linked to its path/key. file_storage_mode = file.file_storage? @package_file.package_id = package_id if package_id @package_file.file_name = file_name if file_name if file_storage_mode # package file is in mode LOCAL: we can pass the `file` to the update @package_file.file = file else # package file is in mode REMOTE: don't pass the `file` to the update # instead, pass the new file path. This will move the file # in object storage. @package_file.new_file_path = File.join(file.store_dir, @package_file.file_name) end @package_file.save! end |