Class: Radmin::AdminUI::NavTab
- Inherits:
-
Array
- Object
- Array
- Radmin::AdminUI::NavTab
- Defined in:
- lib/radmin/admin_ui.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<<(*args) ⇒ Object (also: #add)
- #[](id) ⇒ Object
- #add_item(*args) ⇒ Object
-
#initialize(name) ⇒ NavTab
constructor
A new instance of NavTab.
- #visible?(user) ⇒ Boolean
Constructor Details
#initialize(name) ⇒ NavTab
Returns a new instance of NavTab.
12 13 14 15 |
# File 'lib/radmin/admin_ui.rb', line 12 def initialize(name) @name = name @items = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/radmin/admin_ui.rb', line 10 def name @name end |
Instance Method Details
#<<(*args) ⇒ Object Also known as: add
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/radmin/admin_ui.rb', line 25 def <<(*args) = args. item = args.first raise DuplicateTabNameError.new("duplicate tab name '#{item.name}'") if self[item.name] item.tab = self if item.respond_to?(:tab=) if .empty? super(item) else .symbolize_keys! before = .delete(:before) after = .delete(:after) tab_name = before || after if self[tab_name] _index = index(self[tab_name]) _index += 1 unless before insert(_index, item) else super(item) end end end |
#[](id) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/radmin/admin_ui.rb', line 17 def [](id) unless id.kind_of? Fixnum self.find {|| .name.to_s.titleize == id.to_s.titleize } else super end end |
#add_item(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/radmin/admin_ui.rb', line 49 def add_item(*args) = args. .symbolize_keys! before = .delete(:before) after = .delete(:after) tab_name = before || after if self[tab_name] _index = index(self[tab_name]) _index += 1 unless before insert(_index, NavSubItem.new(args.first, args.second)) else add NavSubItem.new(args.first, args.second) end end |
#visible?(user) ⇒ Boolean
64 65 66 |
# File 'lib/radmin/admin_ui.rb', line 64 def visible?(user) any? { |sub_item| sub_item.visible?(user) } end |