Class: MegaBar::TemplateSection

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mega_bar/template_section.rb

Class Method Summary collapse

Class Method Details

.deterministic_id(code_name, template_id) ⇒ Object

Deterministic ID generation for TemplateSections ID range: 13000-13999



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/mega_bar/template_section.rb', line 13

def self.deterministic_id(code_name, template_id)
  # Use code_name and template_id to create unique identifier
  identifier = "#{code_name}_#{template_id}"
  hash = Digest::MD5.hexdigest(identifier)
  base_id = 13000 + (hash.to_i(16) % 1000)
  
  # Check for collisions and increment if needed
  while MegaBar::TemplateSection.exists?(id: base_id)
    base_id += 1
    break if base_id >= 14000  # Don't overflow into next range
  end
  
  base_id
end