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