Class: MegaBar::Layout

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_nameObject

Returns the value of attribute base_name.



32
33
34
# File 'app/models/mega_bar/layout.rb', line 32

def base_name
  @base_name
end

#block_textObject

Returns the value of attribute block_text.



32
33
34
# File 'app/models/mega_bar/layout.rb', line 32

def block_text
  @block_text
end

#make_blockObject

Returns the value of attribute make_block.



32
33
34
# File 'app/models/mega_bar/layout.rb', line 32

def make_block
  @make_block
end

#model_idObject

Returns the value of attribute model_id.



32
33
34
# File 'app/models/mega_bar/layout.rb', line 32

def model_id
  @model_id
end

Class Method Details

.deterministic_id(page_id, name, base_name = nil) ⇒ Object

Deterministic ID generation for Layouts ID range: 5000-5999



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/mega_bar/layout.rb', line 17

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

Instance Method Details

#create_layable_sectionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/mega_bar/layout.rb', line 49

def create_layable_sections
  template = Template.find(self.template_id)
  template.template_sections.each do |section|
    layout_section_hash = { 
      code_name: self.base_name + '_' + section.code_name, 
      block_text: self.block_text, 
      base_name: self.base_name,
      make_block: self.make_block  # Pass the make_block setting to LayoutSection
    }
    # Only pass model_id to main section
    layout_section_hash[:model_id] = self.model_id if section.code_name == 'main'
    
    ls = LayoutSection.create(layout_section_hash)
    layable = Layable.create(layout_section_id: ls.id, template_section_id: section.id, layout_id: self.id)
  end
end