Class: MegaBar::ModelDisplayFormat
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::ModelDisplayFormat
- Defined in:
- app/models/mega_bar/model_display_format.rb
Class Method Summary collapse
-
.deterministic_id(name) ⇒ Object
Deterministic ID generation for ModelDisplayFormats ID range: 26000-26999.
Class Method Details
.deterministic_id(name) ⇒ Object
Deterministic ID generation for ModelDisplayFormats ID range: 26000-26999
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/mega_bar/model_display_format.rb', line 9 def self.deterministic_id(name) # Use name to create unique identifier identifier = "model_display_format_#{name}" hash = Digest::MD5.hexdigest(identifier) base_id = 26000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::ModelDisplayFormat.exists?(id: base_id) base_id += 1 break if base_id >= 27000 # Don't overflow into next range end base_id end |