Class: FastExists::Backends::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_exists/backends/base.rb

Direct Known Subclasses

File, Memory, Null, Redis, RedisBloom

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/fast_exists/backends/base.rb', line 8

def initialize(options = {})
  @options = options
  @expected_elements = options[:expected_elements] || FastExists.configuration.expected_elements
  @false_positive_rate = options[:false_positive_rate] || FastExists.configuration.false_positive_rate
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/fast_exists/backends/base.rb', line 6

def options
  @options
end

Instance Method Details

#add(key) ⇒ Object

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/fast_exists/backends/base.rb', line 14

def add(key)
  raise NotImplementedError, "#{self.class.name}#add is not implemented"
end

#capacityObject



38
39
40
# File 'lib/fast_exists/backends/base.rb', line 38

def capacity
  @expected_elements
end

#clearObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/fast_exists/backends/base.rb', line 22

def clear
  raise NotImplementedError, "#{self.class.name}#clear is not implemented"
end

#contains?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/fast_exists/backends/base.rb', line 18

def contains?(key)
  raise NotImplementedError, "#{self.class.name}#contains? is not implemented"
end

#countObject



34
35
36
# File 'lib/fast_exists/backends/base.rb', line 34

def count
  0
end

#loadObject



30
31
32
# File 'lib/fast_exists/backends/base.rb', line 30

def load
  true
end

#rebuild(enumerable) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/fast_exists/backends/base.rb', line 50

def rebuild(enumerable)
  clear
  enumerable.each do |item|
    add(item)
  end
  save
  true
end

#saveObject



26
27
28
# File 'lib/fast_exists/backends/base.rb', line 26

def save
  true
end

#statsObject



42
43
44
45
46
47
48
# File 'lib/fast_exists/backends/base.rb', line 42

def stats
  {
    backend: self.class.name,
    capacity: capacity,
    count: count
  }
end