Class: Tabby::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tabby/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



32
33
34
# File 'lib/tabby/base.rb', line 32

def initialize
  @commands = []
end

Class Attribute Details

._basedirObject (readonly)

Returns the value of attribute _basedir.



4
5
6
# File 'lib/tabby/base.rb', line 4

def _basedir
  @_basedir
end

._tabsObject (readonly)

Returns the value of attribute _tabs.



5
6
7
# File 'lib/tabby/base.rb', line 5

def _tabs
  @_tabs
end

Instance Attribute Details

#commandsObject

List of commands for the current tab to execute.



24
25
26
# File 'lib/tabby/base.rb', line 24

def commands
  @commands
end

#templateObject

Rendered AppleScript source to be saved to a tempfile.



30
31
32
# File 'lib/tabby/base.rb', line 30

def template
  @template
end

#titleObject

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

#basedirObject

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

#callObject

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