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