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