Class: MegaBar::Block
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::Block
- Defined in:
- app/models/mega_bar/block.rb
Instance Attribute Summary collapse
-
#edit_model_display ⇒ Object
Returns the value of attribute edit_model_display.
-
#index_model_display ⇒ Object
Returns the value of attribute index_model_display.
-
#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.
Class Method Summary collapse
- .by_actions(action) ⇒ Object
-
.deterministic_id(layout_section_id, name) ⇒ Object
Deterministic ID generation for Blocks ID range: 7000-7999.
Instance Method Summary collapse
Instance Attribute Details
#edit_model_display ⇒ Object
Returns the value of attribute edit_model_display.
16 17 18 |
# File 'app/models/mega_bar/block.rb', line 16 def edit_model_display @edit_model_display end |
#index_model_display ⇒ Object
Returns the value of attribute index_model_display.
16 17 18 |
# File 'app/models/mega_bar/block.rb', line 16 def index_model_display @index_model_display end |
#model_id ⇒ Object
Returns the value of attribute model_id.
16 17 18 |
# File 'app/models/mega_bar/block.rb', line 16 def model_id @model_id end |
#new_model_display ⇒ Object
Returns the value of attribute new_model_display.
16 17 18 |
# File 'app/models/mega_bar/block.rb', line 16 def new_model_display @new_model_display end |
#show_model_display ⇒ Object
Returns the value of attribute show_model_display.
16 17 18 |
# File 'app/models/mega_bar/block.rb', line 16 def show_model_display @show_model_display end |
Class Method Details
.by_actions(action) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/mega_bar/block.rb', line 38 def self.by_actions(action) if action.present? case action when 'show' where(actions: ['all', 'sine', 'show', 'current']) when 'index' where(actions: ['all', 'sine', 'index', 'current']) when 'new' where(actions: ['all', 'sine', 'new', 'current']) when 'edit' where(actions: ['all', 'sine', 'edit', 'current']) when 'create' where(actions: ['all', 'current']) when 'update' where(actions: ['all', 'current']) when 'destroy' where(actions: ['all', 'current']) else where(actions: ['all', 'current', action]) end end end |
.deterministic_id(layout_section_id, name) ⇒ Object
Deterministic ID generation for Blocks ID range: 7000-7999
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/mega_bar/block.rb', line 23 def self.deterministic_id(layout_section_id, name) # Use layout_section_id and name to create unique identifier identifier = "#{layout_section_id}_#{name}" hash = Digest::MD5.hexdigest(identifier) base_id = 7000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::Block.exists?(id: base_id) base_id += 1 break if base_id >= 8000 # Don't overflow into next range end base_id end |
Instance Method Details
#add_route ⇒ Object
75 76 77 78 79 |
# File 'app/models/mega_bar/block.rb', line 75 def add_route return unless saved_changes["path_base"].present? and saved_changes["path_base"][1].present? return if ENV['RAILS_ENV'] == 'test' Rails.application.reload_routes! end |
#make_model_displays ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/mega_bar/block.rb', line 61 def make_model_displays if (!self.model_id.nil? && !self.model_id.to_s.empty? && Integer(self.model_id) > 0) model_name = Model.find(self.model_id).name actions = [] actions << { :format =>2, :action=>'new', :header=>'Create ' + model_name.humanize.singularize, collection_or_member: 'member'} if (!ModelDisplay.by_block(self.id).by_action('new').present? && @new_model_display) actions << {:format=>2, :action=>'edit', :header=>'Edit ' + model_name.humanize.singularize, collection_or_member: 'member'} if (!ModelDisplay.by_block(self.id).by_action('edit').present? && @edit_model_display) actions << {:format=>1, :action=>'index', :header=>model_name.humanize.pluralize, collection_or_member: 'collection'} if (!ModelDisplay.by_block(self.id).by_action('index').present? && @index_model_display) actions << {:format=>2, :action=>'show', :header=>model_name.humanize.singularize, collection_or_member: 'member'} if (!ModelDisplay.by_block(self.id).by_action('show').present? && @show_model_display) actions.each do | action | md = ModelDisplay.create(:block_id=>self.id, model_id: self.model_id, :format=>action[:format], :action=>action[:action], :header=>action[:header], collection_or_member: action[:collection_or_member]) end end end |