Sha256: 0e9f65a26757ddd87cee10a9597f4aefb7134be157405751e2e90b78d5fb7918
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
module Tabulous class Tab attr_reader :name, :parent attr_accessor :subtabs def initialize(name, text, path, visible, enabled) @name = name name = name.to_s if name.ends_with? '_tab' @kind = :tab elsif name.ends_with? '_subtab' @kind = :subtab else raise TabNameError, "Incorrect tab name: '#{name}'. Tab names must end with _tab or _subtab." end @text = text @path = path @visible = visible @enabled = enabled @subtabs = [] end def add_parent(tab) @parent = tab @parent.subtabs = @parent.subtabs + [self] end def subtab? @kind == :subtab end def text(view) if @text.is_a? Proc run_closure(view, @text) else @text end end def path(view) if @path.is_a? Proc run_closure(view, @path) else @path end end def visible?(view) if @visible.is_a? Proc !!run_closure(view, @visible) else !!@visible end end def enabled?(view) if @enabled.is_a? Proc !!run_closure(view, @enabled) else !!@enabled end end private def run_closure(view, closure) if view.respond_to? :instance_exec view.instance_exec(&closure) # for Ruby 1.9 else view.instance_eval(&closure) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tabulous-0.0.2 | lib/tabulous/tab.rb |
tabulous-0.0.1 | lib/tabulous/tab.rb |