Class: Mafia::Generator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Mafia::Generator
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/mafia.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_rakefile ⇒ Object
- #copy_readme ⇒ Object
- #create_app_file ⇒ Object
- #create_bin_file ⇒ Object
- #create_config_ru_file ⇒ Object
- #create_empty_files_and_directories ⇒ Object
- #create_gem_file ⇒ Object
- #create_gemfile ⇒ Object
- #create_gemspec_file ⇒ Object
- #create_license ⇒ Object
- #create_version_file ⇒ Object
- #initalize_git_repo ⇒ Object
- #run_bundle_command ⇒ Object
- #show_complete_message ⇒ Object
Methods included from Helpers
Class Method Details
.source_root ⇒ Object
17 18 19 |
# File 'lib/mafia.rb', line 17 def self.source_root File.(File.join(File.dirname(__FILE__), 'mafia/templates')) end |
Instance Method Details
#copy_rakefile ⇒ Object
47 48 49 |
# File 'lib/mafia.rb', line 47 def copy_rakefile copy_file("Rakefile", "#{name}/Rakefile") end |
#copy_readme ⇒ Object
55 56 57 |
# File 'lib/mafia.rb', line 55 def copy_readme template("README.md.tt", "#{name}/README.md") end |
#create_app_file ⇒ Object
43 44 45 |
# File 'lib/mafia.rb', line 43 def create_app_file template("app.rb.tt", "#{name}/lib/#{name}/app.rb") end |
#create_bin_file ⇒ Object
65 66 67 68 69 70 |
# File 'lib/mafia.rb', line 65 def create_bin_file if yes? "\n\nCreate a binary to run your application?", :green template("bin.tt", "#{name}/bin/#{name}") inject_into_file "#{name}/#{name}.gemspec", "\n s.add_dependency \"thor\"", :after => "s.add_dependency \"sinatra\", \"1.3.1\"" end end |
#create_config_ru_file ⇒ Object
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_directories ⇒ Object
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_file ⇒ Object
39 40 41 |
# File 'lib/mafia.rb', line 39 def create_gem_file template("gem.rb.tt", "#{name}/lib/#{name}.rb") end |
#create_gemfile ⇒ Object
51 52 53 |
# File 'lib/mafia.rb', line 51 def create_gemfile template("Gemfile.tt", "#{name}/Gemfile") end |
#create_gemspec_file ⇒ Object
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_license ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mafia.rb', line 72 def create_license if yes? "\n\nUse MIT License?", :green 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_file ⇒ Object
35 36 37 |
# File 'lib/mafia.rb', line 35 def create_version_file template("version.rb.tt", "#{name}/lib/version.rb") end |
#initalize_git_repo ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/mafia.rb', line 85 def initalize_git_repo target = File.join(Dir.pwd, name) say "\n\nInitializating git repo in #{target}", :green Dir.chdir(target) { run "git init", :verbose => false run "git add .", :verbose => false } end |
#run_bundle_command ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/mafia.rb', line 94 def run_bundle_command target = File.join(Dir.pwd, name) say "\n\nRunning Bundler", :green Dir.chdir(target) { run "bundle install", :verbose => false } end |
#show_complete_message ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mafia.rb', line 102 def complete = <<-COMPLETE Sinatra gem has been generated For help using sinatra please visit www.sinatrarb.com COMPLETE say complete, :green end |