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:
Javi Martín
2024-04-15 20:13:04 +02:00
parent faf765b5c6
commit ce7acbbff7
3 changed files with 32 additions and 6 deletions

View File

@@ -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