class Faker::UniqueGenerator
Constants
- RetryLimitExceeded
Public Class Methods
Source
# File lib/helpers/unique_generator.rb, line 48 def self.clear marked_unique.each(&:clear) marked_unique.clear end
Source
# File lib/helpers/unique_generator.rb, line 44 def self.marked_unique Thread.current[:faker_unique_generator_marked_unique] ||= Set.new end
Source
# File lib/helpers/unique_generator.rb, line 5 def initialize(generator, max_retries) @generator = generator @max_retries = max_retries end
Public Instance Methods
Source
# File lib/helpers/unique_generator.rb, line 40 def clear previous_results.clear end
Source
# File lib/helpers/unique_generator.rb, line 53 def exclude(name, arguments, values) values ||= [] values.each do |value| previous_results[[name, arguments]] << value end end
Source
# File lib/helpers/unique_generator.rb, line 10 def method_missing(name, *arguments) self.class.marked_unique.add(self) @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
Source
# File lib/helpers/unique_generator.rb, line 35 def previous_results Thread.current[:faker_unique_generator_previous_results] ||= {} Thread.current[:faker_unique_generator_previous_results][@generator] ||= Hash.new { |hash, key| hash[key] = Set.new } end
Source
# File lib/helpers/unique_generator.rb, line 29 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('faker_') || super end
Calls superclass method