6 class DuplicateTabNameError < StandardError; end
9 attr_accessor :name, :url, :visibility
11 def initialize(name, url, options = {})
12 @name, @url = name, url
13 @visibility = [options[:for], options[:visibility]].flatten.compact
14 @visibility = [:all] if @visibility.empty?
18 visibility.include?(:all) or
19 visibility.any? { |role| user.send("#{role}?") }
28 def add(name, url, options = {})
29 options.symbolize_keys!
30 before = options.delete(:before)
31 after = options.delete(:after)
32 tab_name = before || after
34 raise DuplicateTabNameError.new("duplicate tab name `#{name}'")
37 index = @tabs.index(self[tab_name])
38 index += 1 if before.nil?
39 @tabs.insert(index, Tab.new(name, url, options))
41 @tabs << Tab.new(name, url, options)
47 @tabs.delete(self[name])
55 if index.kind_of? Integer
58 @tabs.find { |tab| tab.name == index }
63 @tabs.each { |t| yield t }