Class: MegaBar::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::Page
- Defined in:
- app/models/mega_bar/page.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.
-
#make_layout_and_block ⇒ Object
Returns the value of attribute make_layout_and_block.
-
#model_id ⇒ Object
Returns the value of attribute model_id.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
Class Method Summary collapse
-
.deterministic_id(path, name) ⇒ Object
Deterministic ID generation for Pages ID range: 4000-4999.
Instance Method Summary collapse
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def base_name @base_name end |
#block_text ⇒ Object
Returns the value of attribute block_text.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def block_text @block_text end |
#make_layout_and_block ⇒ Object
Returns the value of attribute make_layout_and_block.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def make_layout_and_block @make_layout_and_block end |
#model_id ⇒ Object
Returns the value of attribute model_id.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def model_id @model_id end |
#template_id ⇒ Object
Returns the value of attribute template_id.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def template_id @template_id end |
Class Method Details
.deterministic_id(path, name) ⇒ Object
Deterministic ID generation for Pages ID range: 4000-4999
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/mega_bar/page.rb', line 15 def self.deterministic_id(path, name) # Use path and name to create unique identifier identifier = "#{path}_#{name}" hash = Digest::MD5.hexdigest(identifier) base_id = 4000 + (hash.to_i(16) % 1000) # Check for collisions and increment if needed while MegaBar::Page.exists?(id: base_id) base_id += 1 break if base_id >= 5000 # Don't overflow into next range end base_id end |
Instance Method Details
#add_route ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/mega_bar/page.rb', line 58 def add_route return if ENV['RAILS_ENV'] == 'test' Rails.application.reload_routes! # this now just adds it to the spec_helper. gem_path = '' # line = ' ##### MEGABAR END' # text = File.read('spec/spec_helper.rb') # if self.model_id # mod = Model.find(self.model_id) # gem_path = Rails.root + '../megabar/' if File.directory?(Rails.root + '../megabar/') && mod.modyule == 'MegaBar' # route_text = ' resources :' + mod.classname.downcase.pluralize # route_text += ", path: '#{self.path}'" if '/' + mod.tablename != self.path # route_text += "\n #{line}" # else # route_text = "get '#{self.path}', to: 'flats#index'" # route_text += "\n #{line}" # end # new_contents = text.gsub( /(#{Regexp.escape(line)})/mi, route_text) # # To write changes to the file, use: # File.open(gem_path + 'spec/spec_helper.rb', "w") {|file| file.puts new_contents } # unless gem_path == '' && mod.modyule == 'MegaBar' # @@notices << "You will have to add the route yourself manually to the megabar route file: #{route_text}" if gem_path == '' && modyule == 'MegaBar' end |
#create_layout_for_page ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/mega_bar/page.rb', line 41 def create_layout_for_page base_name = (self.base_name.nil? || self.base_name.empty?) ? self.name : self.base_name template_id = self.template_id.present? ? self.template_id : self.make_layout_and_block # Preserve case in layout name, and pass make_layout_and_block setting layout_hash = { page_id: self.id, name: base_name + ' Layout', base_name: base_name, make_block: self.make_layout_and_block, model_id: self.model_id, template_id: template_id } layout_hash = layout_hash.merge({block_text: self.block_text}) if self.block_text _layout = Layout.create(layout_hash) if (!Layout.by_page(self.id).present? && template_id.present?) end |