module HorsePower class SetupGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) def sprint create_file_structure all_gems run_bundle rspec api_controller include_middleware make_admin routes setup_routes make_user run "rake railties:install:migrations" run_db_migrations make_controllers custom_active_admin seed_database initializers run "wheneverize" #run_git end private def setup_routes inject_into_file "config/routes.rb", after: "root to: \"app_index#app\"\n" do <<-'RUBY' #root to: "controller_name#index" scope 'api' do scope '1' do #/api/1/controller_name #resources :controller_name, controller: 'api/v1/controller_name' #resources :controller_name2, controller: 'api/v1/controller_name2' do #collection do #/api/1/controller_name2/action #post 'action', to: "api/v1/controller_name2#action" #end #end end end #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#- RUBY end end def initializers run "rails g horse_power:app_environment" end def seed_database #db/seeds.rb inject_into_file "db/seeds.rb", after: "# Mayor.create(name: 'Emanuel', city: cities.first)\n" do <<-'RUBY' ::Defcon::AdminUser.create({username: "admin", password: "password", password_confirmation: "password"}) RUBY end run "rake db:seed" end def custom_active_admin template "active_admin_token_register.rb.erb", "app/admin/arcadex_token.rb" end def make_admin run "rails g horse_power:make_admin" end def make_user run "rails g horse_power:user" run_bundle end def include_middleware inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY' #So Rails-Api doesn't remove all of the middleware config.api_only = false RUBY end end def routes route "mount Defcon::Engine, at: \'/\'" route "root to: \"app_index#app\"" end def make_controllers generate "controller", "app_index app" run "rm -f spec/controllers/app_index_controller_spec.rb" copy_file "app_index_controller_spec.rb", "spec/controllers/app_index_controller_spec.rb" run "rm -f app/controllers/app_index_controller.rb" copy_file "app_index_controller.rb", "app/controllers/app_index_controller.rb" #Copy the views over copy_file "views/app", "app/views/app_index/app.html.erb" copy_file "views/app_index", "app/views/layouts/app_index.html.erb" end def api_controller template "application_controller.rb", "app/controllers/api/v1/application_controller.rb" end def rspec generate "rspec:install" run "rm -f .rspec" copy_file "hidden_rspec.rb", ".rspec" copy_file "rspec_factory_girl.rb", "spec/support/factory_girl.rb" inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-'RUBY' config.include ::Requests::JsonHelpers, :type => :request config.include ::Requests::JsonHelpers, :type => :controller RUBY end copy_file "json_helpers.rb", "spec/support/request_helpers.rb" end def all_gems # Dev gems gem_group :development, :test do gem 'figaro', '~> 0.7.0' # env variables gem 'annotate', ">=2.6.0" gem 'rspec-rails', '~> 3.0.0' #gem 'byebug', '~> 3.2.0' gem 'factory_girl_rails', '~> 4.0' gem 'database_cleaner', '~> 1.3.0' end gem_group :development do gem 'better_errors', '~> 1.1.0' gem 'binding_of_caller', '~> 0.7.1' # needed by better_errors or variable inspection end gem 'active_model_serializers', '~> 0.8.0' # This is the api of choice now gem 'rails-api' gem 'kaminari' gem 'bcrypt', '~> 3.1.7' gem 'type_cartographer' gem 'devise', "~> 3.2.4" gem 'arcadex', "~> 1.3.0" gem 'autoprefixer-rails' gem 'bootstrap-sass', '~> 3.2.0' gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master" gem 'defcon' gem 'authorization', :path => "gems/authorization" gem 'whenever', :require => false gem 'rack-cors', :require => 'rack/cors' gem 'httparty' gem 'paperclip', '~> 4.2' gem 'aws-sdk', '~> 1.5.7' gem 'rails_config', '~> 0.4.2' gem 'identity_cache' gem 'cityhash' # optional, for faster hashing (C-Ruby only) #gem 'websocket-rails' end def create_file_structure run "rm -rf test" run "rm -f README.rdoc" run "echo '# Describe your application here' > README.md" run "mkdir engines && touch engines/.gitkeep" run "mkdir gems && touch gems/.gitkeep" run "mkdir notes && touch notes/.gitkeep" run "rails plugin new gems/authorization" end def run_bundle Bundler.with_clean_env do run "bundle install" end end def run_db_migrations run "rake db:migrate RAILS_ENV=development" run "rake db:migrate RAILS_ENV=test" #run "rake db:migrate RAILS_ENV=production" end def run_git git :init git add: "." run "git commit -m \"Initial commit\"" end end end