Class: FFaker::UniqueUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/ffaker/utils/unique_utils.rb

Constant Summary collapse

RetryLimitExceeded =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator, max_retries) ⇒ UniqueUtils

Returns a new instance of UniqueUtils.


5
6
7
8
9
# File 'lib/ffaker/utils/unique_utils.rb', line 5

def initialize(generator, max_retries)
  @generator = generator
  @max_retries = max_retries
  @previous_results = Hash.new { |hash, key| hash[key] = Set.new }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments) ⇒ Object


11
12
13
# File 'lib/ffaker/utils/unique_utils.rb', line 11

def method_missing(name, *arguments)
  @generator.respond_to?(name) ? add_results_to_hash(name, *arguments) : super
end

Class Method Details

.clearObject


25
26
27
# File 'lib/ffaker/utils/unique_utils.rb', line 25

def self.clear
  ObjectSpace.each_object(self, &:clear)
end

Instance Method Details

#clearObject


21
22
23
# File 'lib/ffaker/utils/unique_utils.rb', line 21

def clear
  @previous_results.clear
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:


15
16
17
# File 'lib/ffaker/utils/unique_utils.rb', line 15

def respond_to_missing?(method_name, include_private = false)
  super
end