Extract method to get the tenant root storage
This way we simplify the code a little bit and we create a method unique to the `TenantDiskService` class, which can be used to check whether we're using this class without using `is_a?` or similar.
This commit is contained in:
@@ -2,11 +2,19 @@ require "active_storage/service/disk_service"
|
||||
|
||||
module ActiveStorage
|
||||
class Service::TenantDiskService < Service::DiskService
|
||||
def tenant_root
|
||||
File.join(root, Tenant.subfolder_path)
|
||||
end
|
||||
|
||||
def tenant_root_for(...)
|
||||
File.join(root, Tenant.subfolder_path_for(...))
|
||||
end
|
||||
|
||||
def path_for(key)
|
||||
if Tenant.default?
|
||||
super
|
||||
else
|
||||
super.sub(root, File.join(root, Tenant.subfolder_path))
|
||||
super.sub(root, tenant_root)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user