class Ekylibre::MultiTenancy::TenantRepository
Attributes
private_root[R]
@return [Pathname]
tenants_file[R]
@return [Pathname]
write_mutex[R]
@return [Mutex]
Public Class Methods
new(private_root:, tenants_file:)
click to toggle source
@param [Pathname] private_root
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 14 def initialize(private_root:, tenants_file:) @private_root = private_root @tenants_file = tenants_file @write_mutex = Mutex.new end
Public Instance Methods
delete(name)
click to toggle source
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 30 def delete(name) tenants.delete(name) write end
get(name)
click to toggle source
@param [String] name @return [Tenant, nil]
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 22 def get(name) if has?(name) Tenant.new(name: name, private_directory: private_root.join(name)) else nil end end
has?(name)
click to toggle source
@param [String] name @return [Boolean]
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 38 def has?(name) list.include?(name) end
list()
click to toggle source
@return [Array<String>]
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 43 def list tenants.fetch(::Rails.env.to_s, []) end
Private Instance Methods
load()
click to toggle source
@return [Hash{String => Array<String>}]
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 50 def load if tenants_file.exist? YAML.load_file(tenants_file) || {} else {} end end
tenants()
click to toggle source
@return [Hash{String => Array<String>}]
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 67 def tenants @tenants ||= load end
write()
click to toggle source
# File lib/ekylibre/multi_tenancy/tenant_repository.rb, line 58 def write write_mutex.synchronize do tenants_file.write(tenants.to_yaml) end nil end