Class: Tabby::Runner

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

Constant Summary collapse

TABBYDIR =
File.expand_path("~/.tabby")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
# File 'lib/tabby/runner.rb', line 8

def initialize(argv)
  @project = argv[0]
  @klass   = @project.split("_").map { |p| p.capitalize }.join.to_sym
end

Instance Attribute Details

#projectObject (readonly)

Project name, should be the filename in ~/.tabby.



6
7
8
# File 'lib/tabby/runner.rb', line 6

def project
  @project
end

Instance Method Details

#startObject

Loads the environment file (from ~/.tabby), finds the class which matches the filename and calls it.



16
17
18
19
20
21
22
23
24
25
# File 'lib/tabby/runner.rb', line 16

def start
  require File.join(TABBYDIR, "#{@project}.rb")
  ObjectSpace.class.const_get(@klass).new.call
rescue LoadError
  puts "=> ERROR: Project (#{TABBYDIR}/#{@project}.rb) does not exist."
rescue NameError
  puts "=> ERROR: Project filename/classname mismatch."
  puts "   Filename is:          #{@project}.rb"
  puts "   Classname should be:  #{@klass}"
end