Class: Ferret::Alias_Generator
- Inherits:
-
Object
- Object
- Ferret::Alias_Generator
- Defined in:
- lib/sql-ferret.rb
Instance Method Summary collapse
- #available?(id) ⇒ Boolean
- #create(prefix) ⇒ Object
-
#initialize(used_ids) ⇒ Alias_Generator
constructor
A new instance of Alias_Generator.
- #reserve(id) ⇒ Object
Constructor Details
#initialize(used_ids) ⇒ Alias_Generator
Returns a new instance of Alias_Generator.
445 446 447 448 449 450 |
# File 'lib/sql-ferret.rb', line 445 def initialize used_ids super() @used_ids = Set.new used_ids @counter = 0 return end |
Instance Method Details
#available?(id) ⇒ Boolean
461 462 463 |
# File 'lib/sql-ferret.rb', line 461 def available? id return !@used_ids.include?(id) end |
#create(prefix) ⇒ Object
452 453 454 455 456 457 458 459 |
# File 'lib/sql-ferret.rb', line 452 def create prefix begin @counter += 1 candidate = prefix + @counter.to_s end while @used_ids.include? candidate @used_ids.add candidate return candidate end |
#reserve(id) ⇒ Object
465 466 467 468 469 470 471 |
# File 'lib/sql-ferret.rb', line 465 def reserve id if @used_ids.include? id then ugh 'already-reserved', identifier: id end @used_ids.add id return id end |