Module: SimpleIdentifierGenerator
- Extended by:
- SimpleIdentifierGenerator
- Included in:
- SimpleIdentifierGenerator
- Defined in:
- lib/xcode/simple_identifier_generator.rb
Constant Summary collapse
- MAX_IDENTIFIER_GENERATION_ATTEMPTS =
10
Instance Method Summary collapse
-
#generate(options = {}) ⇒ String
Generate an identifier string.
Instance Method Details
#generate(options = {}) ⇒ String
Generate an identifier string
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/xcode/simple_identifier_generator.rb', line 22 def generate( = {}) existing_keys = [:existing_keys] || [] # Ensure that the identifier generated is unique identifier_generation_count = 0 new_identifier = generate_new_key while existing_keys.include?(new_identifier) new_identifier = generate_new_key # Increment our identifier generation count and if we reach our max raise # an exception as something has gone horribly wrong. identifier_generation_count += 1 if identifier_generation_count > MAX_IDENTIFIER_GENERATION_ATTEMPTS raise "SimpleIdentifierGenerator is unable to generate a unique identifier" end end new_identifier end |