Class: MegaBar::Theme
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::Theme
- Defined in:
- app/models/mega_bar/theme.rb
Class Method Summary collapse
-
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for Themes ID range: 11000-11999.
Class Method Details
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for Themes ID range: 11000-11999
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/mega_bar/theme.rb', line 18 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 = 11000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::Theme.exists?(id: base_id) base_id += 1 break if base_id >= 12000 # Don't overflow into next range end base_id end |