class Faker::UniqueGenerator
Constants
- RetryLimitExceeded
Public Class Methods
clear()
click to toggle source
# File lib/helpers/unique_generator.rb, line 34 def self.clear ObjectSpace.each_object(self, &:clear) end
new(generator, max_retries)
click to toggle source
# File lib/helpers/unique_generator.rb, line 3 def initialize(generator, max_retries) @generator = generator @max_retries = max_retries @previous_results = Hash.new { |hash, key| hash[key] = Set.new } end
Public Instance Methods
clear()
click to toggle source
# File lib/helpers/unique_generator.rb, line 30 def clear @previous_results.clear end
method_missing(name, *arguments)
click to toggle source
rubocop:disable Style/MethodMissingSuper
# File lib/helpers/unique_generator.rb, line 10 def method_missing(name, *arguments) @max_retries.times do result = @generator.public_send(name, *arguments) next if @previous_results[[name, arguments]].include?(result) @previous_results[[name, arguments]] << result return result end raise RetryLimitExceeded, "Retry limit exceeded for #{name}" end
respond_to_missing?(method_name, include_private = false)
click to toggle source
rubocop:enable Style/MethodMissingSuper
Calls superclass method
# File lib/helpers/unique_generator.rb, line 24 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('faker_') || super end