Class: MegaBar::Template
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::Template
- Defined in:
- app/models/mega_bar/template.rb
Class Method Summary collapse
-
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for Templates ID range: 12000-12999.
Class Method Details
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for Templates ID range: 12000-12999
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/mega_bar/template.rb', line 12 def self.deterministic_id(code_name) # Use code_name to create unique identifier identifier = code_name.to_s hash = Digest::MD5.hexdigest(identifier) base_id = 12000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::Template.exists?(id: base_id) base_id += 1 break if base_id >= 13000 # Don't overflow into next range end base_id end |