lib/htcht/cli/rails/rails.rb in htcht-0.1.0 vs lib/htcht/cli/rails/rails.rb in htcht-0.1.1
- old
+ new
@@ -9,38 +9,40 @@
File.dirname(__FILE__)
end
desc 'new AppName', 'Create a new base Rails App inside a Docker Container with Postgres setup as the database.'
method_option :verbose, type: :boolean, default: false, :aliases => '-v', :desc => 'default: [--no-verbose] By default rails new will be run with the quiet flag, this turns it off.'
- method_option :api, type: :boolean, default: false, :desc => 'default: [--no-api] Generate Rails App in API mode.'
- method_option :bootstrap, type: :boolean, default: false, :desc => 'default: [--no-bootstrap] Generate a base Rails app with custom Gemfile and configs. (This along with "--api" is the base for new Rails APIs at Trim Agency).'
+ method_option :api, type: :boolean, default: false, :aliases => '-a', :desc => 'default: [--no-api] Generate Rails App in API mode.'
+ method_option :init, type: :boolean, default: false, :aliases => '-i', :desc => 'default: [--no-init] Generate a base Rails app with custom Gemfile and configs. (This along with "--api" is the base for new Rails APIs at Trim Agency).'
method_option :test, type: :boolean, default: false, :desc => 'default: [--no-test]'
def new(appname)
# Format the appname as snake case for folders, etc.
# This code is taken straight from Rails
+ # TODO: Move to a helper file
snake_name = appname.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
- rails_new_command = 'docker-compose run app rails new . --database=postgresql -T --skip-bundle'
+ rails_new_command = 'docker-compose run app rails new . --database=postgresql --skip-bundle'
# Set the application template
# TODO: Refactor to be dynamic from a directory
- if options[:bootstrap] && options[:api]
- copy_file('templates/api_bootstrap_template.rb', "#{snake_name}/api_bootstrap_template.rb")
+ if options[:init] && options[:api]
+ copy_file('templates/api_init_template.rb', "#{snake_name}/api_init_template.rb")
copy_file('templates/api_build_files/user_spec.rb', "#{snake_name}/build_files/user_spec.rb")
copy_file('templates/api_build_files/users.rb', "#{snake_name}/build_files/users.rb")
copy_file('templates/api_build_files/email_validator.rb', "#{snake_name}/build_files/email_validator.rb")
copy_file('templates/api_build_files/factory_girl.rb', "#{snake_name}/build_files/factory_girl.rb")
copy_file('templates/api_build_files/shoulda_matchers.rb', "#{snake_name}/build_files/shoulda_matchers.rb")
copy_file('templates/api_build_files/rails_helper.rb', "#{snake_name}/build_files/rails_helper.rb")
- rails_new_command.concat(' -m api_bootstrap_template.rb')
- elsif options[:bootstrap]
- puts "--bootstrap must be used with --api for now. This is on it's way"
+ copy_file('templates/api_build_files/seeds.rb', "#{snake_name}/build_files/seeds.rb")
+ rails_new_command.concat(' -m api_init_template.rb -T')
+ elsif options[:init]
+ puts "--init must be used with --api for now."
return
else
copy_file 'templates/default_template.rb', "#{snake_name}/default_template.rb"
rails_new_command.concat(' -m default_template.rb')
end
@@ -84,10 +86,18 @@
run('docker-compose build')
run('docker-compose run app rake db:create')
run('docker-compose run app rake db:migrate')
+ # Clean up the template and build files
+ if options[:init] && options[:api]
+ remove_file("api_init_template.rb")
+ remove_dir("build_files/")
+ else
+ remove_file("default_template.rb")
+ end
end
+
end
end
end
end