Class: Tabby::Base
- Inherits:
-
Object
- Object
- Tabby::Base
- Defined in:
- lib/tabby/base.rb
Class Attribute Summary collapse
-
._basedir ⇒ Object
readonly
Returns the value of attribute _basedir.
-
._tabs ⇒ Object
readonly
Returns the value of attribute _tabs.
Instance Attribute Summary collapse
-
#commands ⇒ Object
List of commands for the current tab to execute.
-
#template ⇒ Object
Rendered AppleScript source to be saved to a tempfile.
-
#title ⇒ Object
Title of the current tab being created.
Class Method Summary collapse
-
.basedir(dir) ⇒ Object
Sets the project root directory.
-
.tab(name, &block) ⇒ Object
define a tab.
Instance Method Summary collapse
-
#basedir ⇒ Object
Project’s base directory.
-
#call ⇒ Object
Call each instance method and create a tab for each one.
-
#exec(command) ⇒ Object
Queue a command to be executed when the tab gets created.
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
32 33 34 |
# File 'lib/tabby/base.rb', line 32 def initialize @commands = [] end |
Class Attribute Details
._basedir ⇒ Object (readonly)
Returns the value of attribute _basedir.
4 5 6 |
# File 'lib/tabby/base.rb', line 4 def _basedir @_basedir end |
._tabs ⇒ Object (readonly)
Returns the value of attribute _tabs.
5 6 7 |
# File 'lib/tabby/base.rb', line 5 def _tabs @_tabs end |
Instance Attribute Details
#commands ⇒ Object
List of commands for the current tab to execute.
24 25 26 |
# File 'lib/tabby/base.rb', line 24 def commands @commands end |
#template ⇒ Object
Rendered AppleScript source to be saved to a tempfile.
30 31 32 |
# File 'lib/tabby/base.rb', line 30 def template @template end |
#title ⇒ Object
Title of the current tab being created.
27 28 29 |
# File 'lib/tabby/base.rb', line 27 def title @title end |
Class Method Details
.basedir(dir) ⇒ Object
Sets the project root directory.
Parameters:
dir Project's root directory path
13 14 15 |
# File 'lib/tabby/base.rb', line 13 def self.basedir(dir) @_basedir = dir end |
.tab(name, &block) ⇒ Object
define a tab
18 19 20 21 |
# File 'lib/tabby/base.rb', line 18 def self.tab(name, &block) @_tabs ||= [] @_tabs << [name, block] end |
Instance Method Details
#basedir ⇒ Object
Project’s base directory. Each tab cd‘s into this directory before executing commands.
68 69 70 |
# File 'lib/tabby/base.rb', line 68 def basedir self.class._basedir end |
#call ⇒ Object
Call each instance method and create a tab for each one. Method names become tab titles, with underscores replaced with spaces.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tabby/base.rb', line 49 def call self.class.instance_methods(false).sort.each do |method| @commands = [] @title = method.gsub("_", " ") send(method) create_tab end self.class._tabs.each do |title, block| @commands = [] @title = title self.instance_exec(&block) create_tab end end |
#exec(command) ⇒ Object
Queue a command to be executed when the tab gets created.
Parameters:
command bash/zsh/etc command to be executed
41 42 43 |
# File 'lib/tabby/base.rb', line 41 def exec(command) @commands << %{write text "#{command}"} end |