Class: MegaBar::LayoutSection
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::LayoutSection
- Defined in:
- app/models/mega_bar/layout_section.rb
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
-
#block_text ⇒ Object
Returns the value of attribute block_text.
-
#edit_model_display ⇒ Object
Returns the value of attribute edit_model_display.
-
#index_model_display ⇒ Object
Returns the value of attribute index_model_display.
-
#make_block ⇒ Object
Returns the value of attribute make_block.
-
#model_id ⇒ Object
Returns the value of attribute model_id.
-
#new_model_display ⇒ Object
Returns the value of attribute new_model_display.
-
#show_model_display ⇒ Object
Returns the value of attribute show_model_display.
-
#template_section_id ⇒ Object
Returns the value of attribute template_section_id.
Class Method Summary collapse
-
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for LayoutSections ID range: 6000-6999.
Instance Method Summary collapse
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def base_name @base_name end |
#block_text ⇒ Object
Returns the value of attribute block_text.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def block_text @block_text end |
#edit_model_display ⇒ Object
Returns the value of attribute edit_model_display.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def edit_model_display @edit_model_display end |
#index_model_display ⇒ Object
Returns the value of attribute index_model_display.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def index_model_display @index_model_display end |
#make_block ⇒ Object
Returns the value of attribute make_block.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def make_block @make_block end |
#model_id ⇒ Object
Returns the value of attribute model_id.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def model_id @model_id end |
#new_model_display ⇒ Object
Returns the value of attribute new_model_display.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def new_model_display @new_model_display end |
#show_model_display ⇒ Object
Returns the value of attribute show_model_display.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def show_model_display @show_model_display end |
#template_section_id ⇒ Object
Returns the value of attribute template_section_id.
3 4 5 |
# File 'app/models/mega_bar/layout_section.rb', line 3 def template_section_id @template_section_id end |
Class Method Details
.deterministic_id(code_name) ⇒ Object
Deterministic ID generation for LayoutSections ID range: 6000-6999
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/mega_bar/layout_section.rb', line 17 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 = 6000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::LayoutSection.exists?(id: base_id) base_id += 1 break if base_id >= 7000 # Don't overflow into next range end base_id end |
Instance Method Details
#create_block_for_section ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/mega_bar/layout_section.rb', line 32 def create_block_for_section # Only create blocks if make_block is explicitly true (from the page form checkbox) return unless self.make_block # path_base: MegaBar::Page.find(self.page_id).path, # could be added in below. but doesnt look necessary. # Separate database attributes from attr_accessors db_attributes = { layout_section_id: self.id, name: self.code_name.humanize + ' Block', actions: 'current' } db_attributes[:html] = self.block_text if self.block_text # Create the block with database attributes only block = Block.new(db_attributes) # Set the attr_accessor attributes if we have a model if self.model_id block.model_id = self.model_id # For model-based pages, create all CRUD displays block.new_model_display = true block.edit_model_display = true block.index_model_display = true block.show_model_display = true end # Save the block (this will trigger callbacks that use the attr_accessors) block.save! block end |