2017-05-01 09:14:35 -04:00
|
|
|
class PersonalFileUploader < FileUploader
|
2018-01-29 12:57:34 -05:00
|
|
|
# Re-Override
|
|
|
|
def self.root
|
|
|
|
options.storage_path
|
2017-05-01 09:14:35 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
def self.base_dir(model)
|
|
|
|
File.join(options.base_dir, model_path_segment(model))
|
2017-06-27 06:53:06 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
def self.model_path_segment(model)
|
|
|
|
return 'temp/' unless model
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
File.join(model.class.to_s.underscore, model.id.to_s)
|
|
|
|
end
|
|
|
|
|
2018-02-21 11:09:30 -05:00
|
|
|
# model_path_segment does not require a model to be passed, so we can always
|
|
|
|
# generate a path, even when there's no model.
|
|
|
|
def model_valid?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
# Revert-Override
|
|
|
|
def store_dir
|
|
|
|
File.join(base_dir, dynamic_segment)
|
2017-05-01 09:14:35 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def secure_url
|
|
|
|
File.join('/', base_dir, secret, file.filename)
|
2017-05-01 09:14:35 -04:00
|
|
|
end
|
|
|
|
end
|