Class: Tabby::Creator

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

Constant Summary collapse

TEMPLATE =
ROOT.join("templates/project.rb.erb")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Creator

Returns a new instance of Creator.



7
8
9
10
# File 'lib/tabby/creator.rb', line 7

def initialize(name)
  @project  = name
  @template = ERB.new(TEMPLATE.expand_path.read)
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#create_project_directoryObject



28
29
30
# File 'lib/tabby/creator.rb', line 28

def create_project_directory
  FileUtils.mkdir_p(TABBYDIR) unless File.directory?(TABBYDIR)
end

#create_project_fileObject



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

def create_project_file
  project_path.open("w") { |f| f << template.result(binding) }
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


23
24
25
# File 'lib/tabby/creator.rb', line 23

def exist?
  project_path.exist?
end

#klassObject



40
41
42
# File 'lib/tabby/creator.rb', line 40

def klass
  project.gsub(/_|-/, " ").split.map { |w| w.capitalize }.join
end

#project_pathObject



36
37
38
# File 'lib/tabby/creator.rb', line 36

def project_path
  TABBYDIR.join("#{project}.rb").expand_path
end

#run!Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/tabby/creator.rb', line 12

def run!
  if exists?
    puts ">> Project already exists."
  else
    create_project_directory
    create_project_file
    puts ">> Successfully created #{@project}."
    Tabby::Editor.new(@project).run!
  end
end