8 class DuplicateTabNameError < StandardError; end
11 attr_accessor :name, :url, :visibility
13 def initialize(name, url, options = {})
14 @name, @url = name, url
15 @visibility = [options[:for], options[:visibility]].flatten.compact
16 @visibility = [:all] if @visibility.empty?
20 visibility.include?(:all) or
21 visibility.any? { |role| user.send("#{role}?") }
30 def add(name, url, options = {})
31 options.symbolize_keys!
32 before = options.delete(:before)
33 after = options.delete(:after)
34 tab_name = before || after
36 raise DuplicateTabNameError.new("duplicate tab name `#{name}'")
39 index = @tabs.index(self[tab_name])
40 index += 1 if before.nil?
41 @tabs.insert(index, Tab.new(name, url, options))
43 @tabs << Tab.new(name, url, options)
49 @tabs.delete(self[name])
57 if index.kind_of? Integer
60 @tabs.find { |tab| tab.name == index }
65 @tabs.each { |t| yield t }