Sha256: 6277d1bb6d091bfa388c86202344be4970c5ef69f9f96daac8dca9e080fbedaf
Contents?: true
Size: 1.88 KB
Versions: 4
Compression:
Stored size: 1.88 KB
Contents
module Effective class MenuItem < ActiveRecord::Base attr_accessor :parent # This gets set on the Root node and a node created by Dropdown, so the item function knows whether to go down or to go accross belongs_to :menu, :inverse_of => :menu_items belongs_to :menuable, :polymorphic => true # Optionaly belong to an object self.table_name = EffectivePages.menu_items_table_name.to_s attr_protected() if Rails::VERSION::MAJOR == 3 acts_as_role_restricted structure do title :string, :validates => [:presence] url :string special :string # divider / search / *_path classes :string new_window :boolean, :default => false, :validates => [:inclusion => {:in => [true, false]}] roles_mask :integer, :default => nil # 0 is going to mean logged in, nil is going to mean public, > 0 will be future implementation of roles masking lft :integer, :validates => [:presence], :index => true rgt :integer, :validates => [:presence] end default_scope -> { includes(:menuable).order(:lft) } def leaf? (rgt.to_i - lft.to_i) == 1 end def dropdown? !leaf? end def divider? leaf? && special == 'divider' end # For now it's just logged in or not? # This will work with effective_roles one day... def visible_for?(user) can_view_page = ( if menuable.kind_of?(Effective::Page) menuable.roles_permit?(user) else true end ) can_view_menu_item = ( if roles_mask == nil true elsif roles_mask == -1 # Am I logged out? user.blank? elsif roles_mask == 0 # Am I logged in? user.present? else roles_permit?(user) end ) can_view_page && can_view_menu_item end end end
Version data entries
4 entries across 4 versions & 1 rubygems