Class: Effective::MenuItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

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



3
4
5
# File 'app/models/effective/menu_item.rb', line 3

def parent
  @parent
end

Instance Method Details

#divider?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/effective/menu_item.rb', line 45

def divider?
  leaf? && special == 'divider'
end

Returns:

  • (Boolean)


41
42
43
# File 'app/models/effective/menu_item.rb', line 41

def dropdown?
  !leaf?
end

#leaf?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/effective/menu_item.rb', line 37

def leaf?
  (rgt.to_i - lft.to_i) == 1
end

#visible_for?(user) ⇒ Boolean

For now it’s just logged in or not? This will work with effective_roles one day…

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/effective/menu_item.rb', line 51

def visible_for?(user)
  can_view_page = (
    if dropdown?
      true
    elsif 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