Class: NubisRailsBoilerplate::Templates
- Inherits:
-
Object
- Object
- NubisRailsBoilerplate::Templates
- Defined in:
- lib/templates.rb
Class Method Summary collapse
- .expand_skeleton(skeleton, basefile) ⇒ Object
- .get_app_name ⇒ Object
- .patch_module_name(skeleton, app_name) ⇒ Object
- .run_setup_tasks(app_name) ⇒ Object
Class Method Details
.expand_skeleton(skeleton, basefile) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/templates.rb', line 4 def self.(skeleton, basefile) skeleton_path = File.absolute_path(File.("../../skeletons/#{skeleton}", basefile)) `cp -r #{skeleton_path} #{get_app_name}` patch_module_name(skeleton, get_app_name) run_setup_tasks(get_app_name) puts "All done! Your app is ready to start customizing." end |
.get_app_name ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/templates.rb', line 32 def self.get_app_name if ARGV.size != 1 puts "Call it like this: #{$0} app_name" exit 1 end unless ARGV[0] =~ /^[a-z_]*$/ puts "The app_name can only be lowercase letters and underscores" exit 1 end return ARGV[0] end |
.patch_module_name(skeleton, app_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/templates.rb', line 12 def self.patch_module_name(skeleton, app_name) puts "Patching #{skeleton} files for #{app_name}" %w(Rakefile config/application.rb config/environment.rb config/environments/development.rb config/environments/test.rb config/environments/production.rb config/initializers/secret_token.rb config/deploy.rb config/database.yml config/initializers/session_store.rb config/routes.rb config.ru).each do |filename| full_path = File.(filename, app_name) new_contents = File.read(full_path) .gsub(skeleton.camelize, app_name.camelize) .gsub(skeleton, app_name) File.write(full_path, new_contents) end end |
.run_setup_tasks(app_name) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/templates.rb', line 25 def self.run_setup_tasks(app_name) puts "Installing gems and configuring databases" Dir.chdir(app_name) do `bundle install; rake db:create; rake db:migrate; rake db:test:prepare` end end |