Class: Mafia::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/mafia.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#camelize

Class Method Details

.source_rootObject



17
18
19
# File 'lib/mafia.rb', line 17

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), 'mafia/templates'))
end

Instance Method Details

#copy_gemfileObject



51
52
53
# File 'lib/mafia.rb', line 51

def copy_gemfile
  copy_file("Gemfile", "#{name}/Gemfile")
end

#copy_rakefileObject



47
48
49
# File 'lib/mafia.rb', line 47

def copy_rakefile
  copy_file("Rakefile", "#{name}/Rakefile")
end

#copy_readmeObject



55
56
57
# File 'lib/mafia.rb', line 55

def copy_readme
  template("README.md.tt", "#{name}/README.md")
end

#create_app_fileObject



43
44
45
# File 'lib/mafia.rb', line 43

def create_app_file
  template("app.rb.tt", "#{name}/lib/#{name}/app.rb")
end

#create_config_ru_fileObject



31
32
33
# File 'lib/mafia.rb', line 31

def create_config_ru_file
  template("config.ru.tt", "#{name}/config.ru")
end

#create_empty_files_and_directoriesObject



59
60
61
62
63
# File 'lib/mafia.rb', line 59

def create_empty_files_and_directories
  empty_directory("#{name}/lib/#{name}/public")
  empty_directory("#{name}/lib/#{name}/views")
  empty_directory("#{name}/lib/#{name}/lib")      
end

#create_gem_fileObject



39
40
41
# File 'lib/mafia.rb', line 39

def create_gem_file
  template("gem.rb.tt", "#{name}/lib/#{name}.rb")
end

#create_gemspec_fileObject



21
22
23
24
25
26
27
28
29
# File 'lib/mafia.rb', line 21

def create_gemspec_file
  opts = {
    :name => name,
    :creator_name => `git config user.name`.chomp,
    :creator_email => `git config user.email`.chomp
  }
  
  template("gemspec.tt", "#{name}/#{name}.gemspec", opts)
end

#create_licenseObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mafia.rb', line 65

def create_license
  if yes? "Use MIT License?"
    
    opts = {
      :name => name,
      :creator_name => `git config user.name`.chomp,
      :creator_email => `git config user.email`.chomp
    }
    
    template("LICENSE.tt", "#{name}/LICENSE", opts)
  end
end

#create_version_fileObject



35
36
37
# File 'lib/mafia.rb', line 35

def create_version_file
  template("version.rb.tt", "#{name}/lib/version.rb")
end

#initalize_git_repoObject



78
79
80
81
82
# File 'lib/mafia.rb', line 78

def initalize_git_repo
  target = File.join(Dir.pwd, name)
  say "Initializating git repo in #{target}"
  Dir.chdir(target) { `git init`; `git add .` }
end