Class: FastExists::MultiTenant::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_exists/multi_tenant/pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, expected_elements:, false_positive_rate: 0.001, backend_type: nil) ⇒ Pool

Returns a new instance of Pool.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fast_exists/multi_tenant/pool.rb', line 8

def initialize(name:, expected_elements:, false_positive_rate: 0.001, backend_type: nil)
  @name = name
  @expected_elements = expected_elements
  @false_positive_rate = false_positive_rate
  @backend_type = backend_type || FastExists.configuration.backend
  @key = FastExists::MultiTenant::KeyLayout.pool_key(name)

  @backend = FastExists.backends.fetch(
    @backend_type,
    namespace: "pool:#{name}",
    expected_elements: expected_elements,
    false_positive_rate: false_positive_rate
  )
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



6
7
8
# File 'lib/fast_exists/multi_tenant/pool.rb', line 6

def backend
  @backend
end

#expected_elementsObject (readonly)

Returns the value of attribute expected_elements.



6
7
8
# File 'lib/fast_exists/multi_tenant/pool.rb', line 6

def expected_elements
  @expected_elements
end

#false_positive_rateObject (readonly)

Returns the value of attribute false_positive_rate.



6
7
8
# File 'lib/fast_exists/multi_tenant/pool.rb', line 6

def false_positive_rate
  @false_positive_rate
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/fast_exists/multi_tenant/pool.rb', line 6

def name
  @name
end

Instance Method Details

#add(tenant_id, attribute, value) ⇒ Object



23
24
25
26
# File 'lib/fast_exists/multi_tenant/pool.rb', line 23

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

#clearObject



33
34
35
# File 'lib/fast_exists/multi_tenant/pool.rb', line 33

def clear
  @backend.clear
end

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

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/fast_exists/multi_tenant/pool.rb', line 28

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

#statsObject



37
38
39
# File 'lib/fast_exists/multi_tenant/pool.rb', line 37

def stats
  @backend.stats.merge(pool_name: @name, pool_key: @key)
end