Class: FastExists::MultiTenant::Strategies::PerTenantStrategy

Inherits:
BaseStrategy
  • Object
show all
Defined in:
lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb

Instance Attribute Summary

Attributes inherited from BaseStrategy

#options

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PerTenantStrategy

Returns a new instance of PerTenantStrategy.



7
8
9
10
11
# File 'lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb', line 7

def initialize(options = {})
  super
  @tenant_backends = {}
  @mutex = Mutex.new
end

Instance Method Details

#add(tenant_id, attribute, value) ⇒ Object



13
14
15
16
17
# File 'lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb', line 13

def add(tenant_id, attribute, value)
  backend = tenant_backend_for(tenant_id)
  composite_key = "#{attribute}:#{value}"
  backend.add(composite_key)
end

#classify_tenant(_tenant_id, _record_count) ⇒ Object



25
26
27
# File 'lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb', line 25

def classify_tenant(_tenant_id, _record_count)
  :per_tenant
end

#contains?(tenant_id, attribute, value) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb', line 19

def contains?(tenant_id, attribute, value)
  backend = tenant_backend_for(tenant_id)
  composite_key = "#{attribute}:#{value}"
  backend.contains?(composite_key)
end

#statsObject



29
30
31
32
33
34
35
36
37
# File 'lib/fast_exists/multi_tenant/strategies/per_tenant_strategy.rb', line 29

def stats
  @mutex.synchronize do
    {
      strategy: :per_tenant,
      active_tenant_filters: @tenant_backends.size,
      tenant_keys: @tenant_backends.keys.map { |t| FastExists::MultiTenant::KeyLayout.tenant_key(t) }
    }
  end
end