Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/voyage/app_builder.rb,
lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #accept_defaults ⇒ Object
- #add_admin_links_to_navigation ⇒ Object
- #add_admin_views_for_devise_resource(adding_first_and_last_name) ⇒ Object
- #add_analytics_initializer ⇒ Object
- #add_api_foundation ⇒ Object
- #add_app_css_file ⇒ Object
- #add_auto_annotate_models_rake_task ⇒ Object
- #add_bullet_gem_configuration ⇒ Object
- #add_canard_roles_to_devise_resource ⇒ Object
- #add_custom_routes_for_devise ⇒ Object
- #add_devise_registrations_controller ⇒ Object
- #add_favicon ⇒ Object
- #add_high_voltage_static_pages ⇒ Object
- #add_refills_to_stylesheets ⇒ Object
- #add_rubocop_config ⇒ Object
- #add_specs ⇒ Object
- #add_to_gitignore ⇒ Object
- #add_token_auth ⇒ Object
- #agree?(prompt) ⇒ Boolean
- #authorize_devise_resource_for_index_action ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_active_job ⇒ Object
- #configure_automatic_deployment ⇒ Object
- #configure_background_jobs_for_rspec ⇒ Object
- #configure_capybara_webkit ⇒ Object
- #configure_ci ⇒ Object
-
#configure_generators ⇒ Object
OVERRIDE SUSPENDERS METHODS #.
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_i18n_for_test_environment ⇒ Object
- #configure_quiet_assets ⇒ Object
- #configure_rack_timeout ⇒ Object
- #configure_rspec ⇒ Object
- #configure_rvm_prepend_bin_to_path ⇒ Object
- #configure_simple_form ⇒ Object
- #configure_smtp ⇒ Object
- #configure_spec_support_features ⇒ Object
- #configure_time_formats ⇒ Object
- #copy_dotfiles ⇒ Object
- #copy_env_to_example ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_database ⇒ Object
- #create_deploy_script ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_partials_directory ⇒ Object
- #create_shared_css_overrides ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #customize_application_controller_for_devise(adding_first_and_last_name, devise_token_auth) ⇒ Object
- #customize_application_js ⇒ Object
- #customize_application_mailer ⇒ Object
- #customize_devise_views ⇒ Object
- #customize_error_pages ⇒ Object
- #customize_resource_controller_for_devise(adding_first_and_last_name) ⇒ Object
- #customize_user_factory(adding_first_and_last_name) ⇒ Object
- #customize_user_spec ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #downgrade_neat_1_8_so_refills_media_mixin_works ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_rack_canonical_host ⇒ Object
- #enable_rack_deflater ⇒ Object
- #gemfile ⇒ Object
- #generate_data_migrations ⇒ Object
-
#generate_factories_file ⇒ Object
——————————– setup_test_environment overrides ——————————–.
-
#generate_refills ⇒ Object
————————- ADDING REFILLS COMPONENTS ————————-.
- #generate_rspec ⇒ Object
- #generate_ruby_version_and_gemset ⇒ Object
-
#generate_seeder_templates(using_devise:) ⇒ Object
—————- END DEVISE SETUP —————-.
-
#generate_test_environment ⇒ Object
—————————– END ADDING REFILLS COMPONENTS —————————–.
- #gitignore ⇒ Object
- #init_git ⇒ Object
-
#install_devise ⇒ Object
———— DEVISE SETUP ————.
- #overwrite_application_layout ⇒ Object
- #provide_dev_prime_task ⇒ Object
- #provide_setup_script ⇒ Object
- #provide_shoulda_matchers_config ⇒ Object
- #raise_on_delivery_errors ⇒ Object
- #raise_on_missing_assets_in_test ⇒ Object
- #raise_on_unpermitted_parameters ⇒ Object
-
#rake_db_setup ⇒ Object
Do this last.
- #readme ⇒ Object
-
#remove_config_comment_lines ⇒ Object
———————————— End setup_test_environment overrides ————————————.
- #remove_routes_comment_lines ⇒ Object
- #remove_turbolinks ⇒ Object
- #replace_default_puma_configuration ⇒ Object
- #replace_gemfile(path) ⇒ Object
- #require_files_in_lib ⇒ Object
- #run_rubocop_auto_correct ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #set_test_delivery_method ⇒ Object
- #set_up_factory_girl_for_rspec ⇒ Object
- #set_up_forego ⇒ Object
- #set_up_hound ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_bundler_audit ⇒ Object
- #setup_default_directories ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_rack_mini_profiler ⇒ Object
- #setup_secret_token ⇒ Object
- #setup_segment ⇒ Object
- #setup_spring ⇒ Object
- #spin_up_webpacker ⇒ Object
- #update_application_css_file ⇒ Object
- #update_application_layout_for_slim ⇒ Object
- #update_application_rb_for_slim ⇒ Object
- #update_delayed_job_migration_rails_5_1_specify_4_2 ⇒ Object
- #update_devise_initializer ⇒ Object
- #update_flashes_css_file ⇒ Object
- #update_gemset_in_gemfile ⇒ Object
- #update_test_environment ⇒ Object
- #use_postgres_config_template ⇒ Object
- #use_slim ⇒ Object
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#accept_defaults ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/voyage/app_builder.rb', line 10 def accept_defaults if agree?('Would you like to accept all defaults? [slim, devise w/ first & last name, refills nav & footer] (Y/n)') @@accept_defaults = true else @@accept_defaults = false end end |
#add_admin_links_to_navigation ⇒ Object
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/voyage/app_builder.rb', line 698 def return unless @@use_devise inject_into_file 'app/views/refills/_navigation.html.erb', after: ' <li class="nav-link"><a href="javascript:void(0)">Contact</a></li>' do "\n <% if current_user && true_user.admin? %>\n <% if current_user != true_user %>\n <li class='nav-link'><%= link_to 'Stop Impersonating', stop_impersonating_admin_users_path %></li>\n <% else %>\n <li class=\"nav-link\"><a href=\"/admin/users\">Admin</a></li>\n <% end %>\n <% end %>\n\n <% if current_user %>\n <li class='nav-link'><%= link_to 'Sign Out', sign_out_path %></li>\n <% else %>\n <li class='nav-link'><%= link_to 'Sign In', sign_in_path %></li>\n <% end %>\n RUBY\n end\nend\n" |
#add_admin_views_for_devise_resource(adding_first_and_last_name) ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/voyage/app_builder.rb', line 311 def add_admin_views_for_devise_resource(adding_first_and_last_name) config = { adding_first_and_last_name: adding_first_and_last_name } template '../templates/users_index.html.erb', 'app/views/admin/users/index.html.erb', config if @@use_slim inside('lib') do # arbitrary, run in context of newly generated app run "erb2slim '../app/views/users' '../app/views/users'" run "erb2slim -d '../app/views/users'" run "erb2slim '../app/views/admin/users' '../app/views/admin/users'" run "erb2slim -d '../app/views/admin/users'" end end template '../templates/admin_users_controller.rb', 'app/controllers/admin/users_controller.rb' template '../templates/admin_controller.rb', 'app/controllers/admin/admin_controller.rb' end |
#add_analytics_initializer ⇒ Object
289 290 291 292 |
# File 'lib/voyage/app_builder.rb', line 289 def add_analytics_initializer template '../templates/analytics_ruby_initializer.rb', 'config/initializers/analytics_ruby.rb' template '../templates/analytics_alias.html.erb.erb', 'app/views/users/analytics_alias.html.erb' end |
#add_api_foundation ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/voyage/app_builder.rb', line 558 def add_api_foundation # Create /app/api/base_api_controller.rb template '../templates/api_base_controller.rb', 'app/controllers/api/base_api_controller.rb', force: true # Create /app/api/v1/users_controller.rb template '../templates/api_users_controller.rb', 'app/controllers/api/v1/users_controller.rb', force: true # Update routes to include namespaced API inject_into_file 'config/routes.rb', before: /^end/ do "\n # API-specific routes\n namespace 'api' do\n namespace 'v1' do\n resources :users, except: [:new, :edit]\n end\n end\n RUBY\n end\nend\n".gsub(/^ {6}/, '') |
#add_app_css_file ⇒ Object
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/voyage/app_builder.rb', line 661 def add_app_css_file create_file "app/assets/stylesheets/#{app_name}.sass" do " .outer-wrapper\n position: relative\n min-height: 100%\n\n .navigation-wrapper\n @include outer-container\n\n .main\n padding: 18px\n @include outer-container\n padding-bottom: 450px\n\n .footer\n min-height: 420px\n position: absolute\n bottom: 0\n left: 0\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#add_auto_annotate_models_rake_task ⇒ Object
764 765 766 |
# File 'lib/voyage/app_builder.rb', line 764 def add_auto_annotate_models_rake_task template '../templates/auto_annotate_models.rake', 'lib/tasks/auto_annotate_models.rake', force: true end |
#add_bullet_gem_configuration ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/suspenders/app_builder.rb', line 63 def add_bullet_gem_configuration config = " config.after_initialize do\nBullet.enable = true\nBullet.bullet_logger = true\nBullet.rails_logger = true\n end\n\n RUBY\n\n inject_into_file(\n \"config/environments/development.rb\",\n config,\n after: \"config.action_mailer.raise_delivery_errors = true\\n\",\n )\nend\n" |
#add_canard_roles_to_devise_resource ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/voyage/app_builder.rb', line 360 def add_canard_roles_to_devise_resource inject_into_file 'app/models/user.rb', before: /^end/ do "\n before_create :generate_uuid\n\n # Permissions cascade/inherit through the roles listed below. The order of\n # this list is important, it should progress from least to most privelage\n ROLES = [:admin].freeze\n acts_as_user roles: ROLES\n roles ROLES\n\n validates :email,\n presence: true,\n format: /\\\\A[-a-z0-9_+\\\\.]+\\\\@([-a-z0-9]+\\\\.)+[a-z0-9]{2,8}\\\\z/i,\n uniqueness: true\n\n # NOTE: these password validations won't run if the user has an invite token\n validates :password,\n presence: true,\n length: { within: 8..72 },\n confirmation: true,\n on: :create\n validates :password_confirmation,\n presence: true,\n on: :create\n\n def tester?\n (email =~ /(example.com|headway.io)$/).present?\n end\n\n private\n\n def generate_uuid\n loop do\n uuid = SecureRandom.uuid\n self.uuid = uuid\n break unless User.exists?(uuid: uuid)\n end\n end\n RUBY\n end\nend\n".gsub(/^ {6}/, '') |
#add_custom_routes_for_devise ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/voyage/app_builder.rb', line 412 def add_custom_routes_for_devise find = " devise_for :users\n resources :users\n RUBY\n\n replace = <<-RUBY.gsub(/^ {6}/, '')\n devise_for :users, controllers: {\n registrations: 'devise_customizations/registrations',\n }\n\n resources :users do\n member do\n get 'analytics_alias'\n end\n end\n\n namespace :admin do\n resources :users do\n member do\n get 'impersonate'\n end\n\n collection do\n get 'stop_impersonating'\n end\n end\n end\n\n authenticated :user do\n # root to: 'dashboard#show', as: :authenticated_root\n root to: 'high_voltage/pages#show', id: 'welcome', as: :authenticated_root\n end\n\n devise_scope :user do\n get 'sign-in', to: 'devise/sessions#new'\n get 'sign-out', to: 'devise/sessions#destroy'\n end\n RUBY\n\n replace_in_file 'config/routes.rb', find, replace\nend\n".gsub(/^ {6}/, '') |
#add_devise_registrations_controller ⇒ Object
283 284 285 286 |
# File 'lib/voyage/app_builder.rb', line 283 def add_devise_registrations_controller template '../templates/devise_registrations_controller.rb', 'app/controllers/devise_customizations/registrations_controller.rb' end |
#add_favicon ⇒ Object
773 774 775 |
# File 'lib/voyage/app_builder.rb', line 773 def add_favicon template '../templates/favicon.ico', 'app/assets/images/favicon.ico', force: true end |
#add_high_voltage_static_pages ⇒ Object
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/voyage/app_builder.rb', line 610 def add_high_voltage_static_pages template '../templates/about.html.erb', "app/views/pages/about.html.#{@@use_slim ? 'slim' : 'erb'}" template '../templates/welcome.html.erb', "app/views/pages/welcome.html.erb" inject_into_file 'config/routes.rb', before: /^end/ do " root 'high_voltage/pages#show', id: 'welcome'\n RUBY\n end\n\n create_file 'config/initializers/high_voltage.rb' do <<-RUBY.gsub(/^ {8}/, '')\n HighVoltage.configure do |config|\n config.route_drawer = HighVoltage::RouteDrawers::Root\n end\n RUBY\n end\nend\n".gsub(/^ {6}/, '') |
#add_refills_to_stylesheets ⇒ Object
719 720 721 722 723 724 725 726 727 |
# File 'lib/voyage/app_builder.rb', line 719 def add_refills_to_stylesheets inject_into_file 'app/assets/stylesheets/application.scss', after: '@import "refills/flashes";' do " \\n@import \"refills/navigation\";\n @import \"refills/footer\";\n\n @import \"\#{app_name}\";\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#add_rubocop_config ⇒ Object
760 761 762 |
# File 'lib/voyage/app_builder.rb', line 760 def add_rubocop_config template '../templates/rubocop.yml', '.rubocop.yml', force: true end |
#add_specs ⇒ Object
781 782 783 784 785 786 787 788 789 |
# File 'lib/voyage/app_builder.rb', line 781 def add_specs inject_into_file 'app/jobs/application_job.rb', before: "class ApplicationJob < ActiveJob::Base" do " # :nocov:\n RUBY\n end\n\n template '../templates/specs/controllers/admin/users_controller_spec.rb', 'spec/controllers/admin/users_controller_spec.rb', force: true\n template '../templates/specs/controllers/application_controller_spec.rb', 'spec/controllers/application_controller_spec.rb', force: true\nend\n".gsub(/^ {8}/, '') |
#add_to_gitignore ⇒ Object
822 823 824 825 826 827 828 829 830 831 832 |
# File 'lib/voyage/app_builder.rb', line 822 def add_to_gitignore inject_into_file '.gitignore', after: '/tmp/*' do "\n .env\n .zenflow-log\n errors.err\n .ctags\n .cadre/coverage.vim\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#add_token_auth ⇒ Object
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/voyage/app_builder.rb', line 536 def add_token_auth inject_into_file 'app/models/user.rb', after: "class User < ApplicationRecord" do "\n acts_as_token_authenticatable\n RUBY\n end\n\n generate 'migration add_authentication_token_to_users \"authentication_token:string{30}:uniq\"'\n\n # specs\n template '../templates/specs/features/user_impersonation_spec.rb', 'spec/features/user_impersonation_spec.rb', force: true\n template '../templates/specs/features/user_list_spec.rb', 'spec/features/user_list_spec.rb', force: true\n template '../templates/specs/features/user_signup_spec.rb', 'spec/features/user_signup_spec.rb', force: true\n template '../templates/specs/requests/user_api_spec.rb', 'spec/requests/user_api_spec.rb', force: true\n template '../templates/specs/support/api/schemas/user.json', 'spec/support/api/schemas/user.json', force: true\n template '../templates/config_initializers_ams.rb', 'config/initializers/ams.rb', force: true\n template '../templates/specs/support/matchers/api_schema_matcher.rb', 'spec/support/matchers/api_schema_matcher.rb', force: true\n template '../templates/specs/mailers/application_mailer_spec.rb.erb', 'spec/mailers/application_mailer_spec.rb', force: true\n template '../templates/specs/support/features/session_helpers.rb', 'spec/support/features/session_helpers.rb', force: true\n template '../templates/specs/support/request_spec_helper.rb', 'spec/support/request_spec_helper.rb', force: true\nend\n".gsub(/^ {6}/, '') |
#agree?(prompt) ⇒ Boolean
3 4 5 6 7 8 |
# File 'lib/voyage/app_builder.rb', line 3 def agree?(prompt) puts prompt response = STDIN.gets.chomp response.empty? || %w(y yes).include?(response.downcase.strip) end |
#authorize_devise_resource_for_index_action ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/voyage/app_builder.rb', line 329 def generate 'canard:ability user can:manage:user cannot:destroy:user' generate 'canard:ability admin can:destroy:user' %w(admins users).each do |resource_name| replace_in_file "spec/abilities/#{resource_name}_spec.rb", "require 'cancan/matchers'", "require_relative '../support/matchers/custom_cancan'" end find = " it { is_expected.to be_able_to(:manage, user) }\n RUBY\n replace = <<-RUBY.gsub(/^ {4}/, '')\n it { is_expected.to be_able_to(:manage, acting_user) }\n it { is_expected.to_not be_able_to(:manage, user) }\n RUBY\n replace_in_file 'spec/abilities/users_spec.rb', find, replace\n\n find = <<-RUBY.gsub(/^ {6}/, '')\n can [:manage], User\n RUBY\n replace = <<-RUBY.gsub(/^ {6}/, '')\n can [:manage], User do |u|\n u == user\n end\n RUBY\n replace_in_file 'app/abilities/users.rb', find, replace\n\n generate 'migration add_roles_mask_to_users roles_mask:integer'\n template '../templates/custom_cancan_matchers.rb', 'spec/support/matchers/custom_cancan.rb'\nend\n".gsub(/^ {4}/, '') |
#configure_action_mailer ⇒ Object
312 313 314 315 316 |
# File 'lib/suspenders/app_builder.rb', line 312 def configure_action_mailer action_mailer_host "development", %{"localhost:3000"} action_mailer_host "test", %{"www.example.com"} action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")} end |
#configure_action_mailer_in_specs ⇒ Object
287 288 289 |
# File 'lib/suspenders/app_builder.rb', line 287 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_active_job ⇒ Object
318 319 320 321 322 323 |
# File 'lib/suspenders/app_builder.rb', line 318 def configure_active_job configure_application_file( "config.active_job.queue_adapter = :delayed_job" ) configure_environment "test", "config.active_job.queue_adapter = :inline" end |
#configure_automatic_deployment ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/suspenders/app_builder.rb', line 382 def configure_automatic_deployment deploy_command = " deployment:\n staging:\n branch: master\n commands:\n - bin/deploy staging\n YML\n\n append_file \"circle.yml\", deploy_command\nend\n".strip_heredoc |
#configure_background_jobs_for_rspec ⇒ Object
888 889 890 891 892 |
# File 'lib/voyage/app_builder.rb', line 888 def configure_background_jobs_for_rspec # template '../templates/config_dj_rails5_patches.rb', 'config/dj_rails5_patches.rb', force: true run 'rails g delayed_job:active_record' end |
#configure_capybara_webkit ⇒ Object
894 895 896 |
# File 'lib/voyage/app_builder.rb', line 894 def # NOTE: (2016-02-03) jonk => don't want this end |
#configure_ci ⇒ Object
884 885 886 |
# File 'lib/voyage/app_builder.rb', line 884 def configure_ci template "circle.yml.erb", "circle.yml" end |
#configure_generators ⇒ Object
OVERRIDE SUSPENDERS METHODS #
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
# File 'lib/voyage/app_builder.rb', line 842 def configure_generators config = "\n config.generators do |g|\n g.helper false\n g.javascript_engine false\n g.request_specs false\n g.routing_specs false\n g.stylesheets false\n g.test_framework :rspec\n g.view_specs false\n g.fixture_replacement :factory_girl, dir: 'spec/factories'\n end\n\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n".gsub(/^ {4}/, '') |
#configure_i18n_for_missing_translations ⇒ Object
278 279 280 281 |
# File 'lib/suspenders/app_builder.rb', line 278 def configure_i18n_for_missing_translations raise_on_missing_translations_in("development") raise_on_missing_translations_in("test") end |
#configure_i18n_for_test_environment ⇒ Object
274 275 276 |
# File 'lib/suspenders/app_builder.rb', line 274 def configure_i18n_for_test_environment copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_quiet_assets ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/suspenders/app_builder.rb', line 88 def configure_quiet_assets config = "config.assets.quiet = true\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n" |
#configure_rack_timeout ⇒ Object
300 301 302 303 304 305 306 |
# File 'lib/suspenders/app_builder.rb', line 300 def configure_rack_timeout rack_timeout_config = "Rack::Timeout.timeout = (ENV[\"RACK_TIMEOUT\"] || 10).to_i\n RUBY\n\n append_file \"config/environments/production.rb\", rack_timeout_config\nend\n" |
#configure_rspec ⇒ Object
263 264 265 266 267 268 |
# File 'lib/suspenders/app_builder.rb', line 263 def configure_rspec remove_file "spec/rails_helper.rb" remove_file "spec/spec_helper.rb" copy_file "rails_helper.rb", "spec/rails_helper.rb" copy_file "spec_helper.rb", "spec/spec_helper.rb" end |
#configure_rvm_prepend_bin_to_path ⇒ Object
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
# File 'lib/voyage/app_builder.rb', line 797 def configure_rvm_prepend_bin_to_path run "rm -f $rvm_path/hooks/after_cd_bundler" run "touch $rvm_path/hooks/after_cd_bundler" git_safe_dir = " #!/usr/bin/env bash\n export PATH=\".git/safe/../../bin:$PATH\"\n RUBY\n\n run \"echo '\#{git_safe_dir}' >> $rvm_path/hooks/after_cd_bundler\"\n\n run 'chmod +x $rvm_path/hooks/after_cd_bundler'\n\n run 'mkdir -p .git/safe'\nend\n".gsub(/^ {8}/, '') |
#configure_simple_form ⇒ Object
308 309 310 |
# File 'lib/suspenders/app_builder.rb', line 308 def configure_simple_form bundle_command "exec rails generate simple_form:install" end |
#configure_smtp ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/suspenders/app_builder.rb', line 135 def configure_smtp copy_file 'smtp.rb', 'config/smtp.rb' prepend_file 'config/environments/production.rb', %{require Rails.root.join("config/smtp")\n} config = "\n config.action_mailer.delivery_method = :smtp\n config.action_mailer.smtp_settings = SMTP_SETTINGS\n RUBY\n\n inject_into_file 'config/environments/production.rb', config,\n after: \"config.action_mailer.raise_delivery_errors = false\"\nend\n" |
#configure_spec_support_features ⇒ Object
258 259 260 261 |
# File 'lib/suspenders/app_builder.rb', line 258 def configure_spec_support_features empty_directory_with_keep_file 'spec/features' empty_directory_with_keep_file 'spec/support/features' end |
#configure_time_formats ⇒ Object
295 296 297 298 |
# File 'lib/suspenders/app_builder.rb', line 295 def configure_time_formats remove_file "config/locales/en.yml" template "config_locales_en.yml.erb", "config/locales/en.yml" end |
#copy_dotfiles ⇒ Object
351 352 353 |
# File 'lib/suspenders/app_builder.rb', line 351 def copy_dotfiles directory("dotfiles", ".") end |
#copy_env_to_example ⇒ Object
818 819 820 |
# File 'lib/voyage/app_builder.rb', line 818 def copy_env_to_example run 'cp .env .env.example' end |
#copy_miscellaneous_files ⇒ Object
412 413 414 415 416 |
# File 'lib/suspenders/app_builder.rb', line 412 def copy_miscellaneous_files copy_file "browserslist", "browserslist" copy_file "errors.rb", "config/initializers/errors.rb" copy_file "json_encoding.rb", "config/initializers/json_encoding.rb" end |
#create_application_layout ⇒ Object
218 219 220 221 222 |
# File 'lib/suspenders/app_builder.rb', line 218 def create_application_layout template 'suspenders_layout.html.erb.erb', 'app/views/layouts/application.html.erb', force: true end |
#create_database ⇒ Object
872 873 874 875 |
# File 'lib/voyage/app_builder.rb', line 872 def create_database # Suspenders version also migrates, we don't want that yet... we migrate in the rake_db_setup method bundle_command 'exec rake db:create' end |
#create_deploy_script ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/suspenders/app_builder.rb', line 364 def create_deploy_script copy_file "bin_deploy", "bin/deploy" instructions = "\n## Deploying\n\nIf you have previously run the `./bin/setup` script,\nyou can deploy to staging and production with:\n\n% ./bin/deploy staging\n% ./bin/deploy production\n MARKDOWN\n\n append_file \"README.md\", instructions\n run \"chmod a+x bin/deploy\"\nend\n" |
#create_github_repo(repo_name) ⇒ Object
394 395 396 |
# File 'lib/suspenders/app_builder.rb', line 394 def create_github_repo(repo_name) run "hub create #{repo_name}" end |
#create_heroku_apps(flags) ⇒ Object
359 360 361 362 |
# File 'lib/suspenders/app_builder.rb', line 359 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_partials_directory ⇒ Object
198 199 200 |
# File 'lib/suspenders/app_builder.rb', line 198 def create_partials_directory empty_directory 'app/views/application' end |
#create_shared_css_overrides ⇒ Object
211 212 213 214 215 216 |
# File 'lib/suspenders/app_builder.rb', line 211 def create_shared_css_overrides copy_file( "_css_overrides.html.erb", "app/views/application/_css_overrides.html.erb", ) end |
#create_shared_flashes ⇒ Object
202 203 204 205 |
# File 'lib/suspenders/app_builder.rb', line 202 def create_shared_flashes copy_file "_flashes.html.erb", "app/views/application/_flashes.html.erb" copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb" end |
#create_shared_javascripts ⇒ Object
207 208 209 |
# File 'lib/suspenders/app_builder.rb', line 207 def create_shared_javascripts copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb' end |
#customize_application_controller_for_devise(adding_first_and_last_name, devise_token_auth) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/voyage/app_builder.rb', line 158 def customize_application_controller_for_devise(adding_first_and_last_name, devise_token_auth) inject_into_file 'app/controllers/application_controller.rb', before: "class ApplicationController < ActionController::Base" do " # rubocop:disable Metrics/ClassLength, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/LineLength\n RUBY\n end\n\n inject_into_file 'app/controllers/application_controller.rb', after: \" protect_from_forgery with: :exception\" do <<-RUBY.gsub(/^ {6}/, '')\n\n check_authorization unless: :devise_or_pages_controller?\n impersonates :user\n \#{'acts_as_token_authentication_handler_for User' if devise_token_auth}\n\n before_action :configure_permitted_parameters, if: :devise_controller?\n before_action :authenticate_user!, unless: -> { is_a?(HighVoltage::PagesController) }\n before_action :add_layout_name_to_gon\n before_action :detect_device_type\n\n rescue_from CanCan::AccessDenied do |exception|\n redirect_to root_path, alert: exception.message\n end\n\n # Example Traditional Event: analytics_track(user, 'Created Widget', { widget_name: 'foo' })\n # Example Page View: analytics_track(user, 'Page Viewed', { page_name: 'Terms and Conditions', url: '/terms' })\n #\n # NOTE: setup some defaults that we want to track on every event mixpanel_track\n # NOTE: the identify step happens on every page load to keep intercom.io and mixpanel people up to date\n def analytics_track(user, event_name, options = {})\n return if user.tester?\n\n sanitized_options = sanitize_hash_javascript(options)\n\n segment_attributes = {\n user_id: user.uuid,\n event: event_name,\n properties: {\n browser: \"\\\#{browser.name rescue 'unknown'}\",\n browser_id: \"\\\#{browser.id rescue 'unknown'}\",\n browser_version: \"\\\#{browser.version rescue 'unknown'}\",\n platform: \"\\\#{browser.platform rescue 'unknown'}\",\n roles: \"\\\#{user.roles.map(&:to_s).join(',') rescue ''}\",\n rails_env: Rails.env.to_s,\n }.merge(sanitized_options),\n }\n\n Analytics.track(segment_attributes)\n end\n\n protected\n\n def devise_or_pages_controller?\n devise_controller? == true || is_a?(HighVoltage::PagesController)\n end\n\n def sanitize_hash_javascript(hash)\n hash.deep_stringify_keys\n .deep_transform_keys { |k| sanitize_javascript(k) }\n .transform_values { |v| sanitize_javascript(v) }\n end\n\n def sanitize_javascript(value)\n value.is_a?(String) ? ActionView::Base.new.escape_javascript(value) : value\n end\n\n def configure_permitted_parameters\n devise_parameter_sanitizer.permit(\n :sign_up,\n keys: [\n \#{':first_name,' if adding_first_and_last_name}\n \#{':last_name,' if adding_first_and_last_name}\n :email,\n :password,\n :password_confirmation,\n :remember_me,\n ],\n )\n\n devise_parameter_sanitizer.permit(\n :sign_in,\n keys: [\n :login, :email, :password, :remember_me\n ],\n )\n\n devise_parameter_sanitizer.permit(\n :account_update,\n keys: [\n \#{':first_name,' if adding_first_and_last_name}\n \#{':last_name,' if adding_first_and_last_name}\n :email,\n :password,\n :password_confirmation,\n :current_password,\n ],\n )\n end\n\n def add_layout_name_to_gon\n gon.layout =\n case devise_controller?\n when true\n 'devise'\n else\n 'application'\n end\n end\n\n def detect_device_type\n request.variant =\n case request.user_agent\n when /iPad/i\n :tablet\n when /iPhone/i\n :phone\n when /Android/i && /mobile/i\n :phone\n when /Android/i\n :tablet\n when /Windows Phone/i\n :phone\n end\n end\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#customize_application_js ⇒ Object
578 579 580 581 582 583 584 585 586 |
# File 'lib/voyage/app_builder.rb', line 578 def customize_application_js template '../templates/application.js', 'app/assets/javascripts/application.js', force: true inject_into_file 'app/views/application/_javascript.html.erb', after: '<%= render "analytics" %>' do "\n <%= render \"analytics_identify\" %>\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#customize_application_mailer ⇒ Object
777 778 779 |
# File 'lib/voyage/app_builder.rb', line 777 def customize_application_mailer template '../templates/application_mailer.rb.erb', 'app/mailers/application_mailer.rb', force: true end |
#customize_devise_views ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/voyage/app_builder.rb', line 138 def customize_devise_views %w(edit new).each do |file| if @@use_slim file_path = "app/views/devise/registrations/#{file}.html.slim" inject_into_file file_path, before: " = f.input :email, required: true, autofocus: true" do " = f.input :first_name, required: true, autofocus: true\n = f.input :last_name, required: true\n RUBY\n end\n else\n file_path = \"app/views/devise/registrations/\#{file}.html.erb\"\n inject_into_file file_path, before: \" <%= f.input :email, required: true, autofocus: true %>\" do <<-'RUBY'.gsub(/^ {8}/, '')\n <%= f.input :first_name, required: true, autofocus: true %>\n <%= f.input :last_name, required: true %>\n RUBY\n end\n end\n end\nend\n".gsub(/^ {8}/, '') |
#customize_error_pages ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/suspenders/app_builder.rb', line 418 def customize_error_pages =" <meta charset=\"utf-8\" />\n <meta name=\"ROBOTS\" content=\"NOODP\" />\n <meta name=\"viewport\" content=\"initial-scale=1\" />\n EOS\n\n %w(500 404 422).each do |page|\n inject_into_file \"public/\#{page}.html\", meta_tags, after: \"<head>\\n\"\n replace_in_file \"public/\#{page}.html\", /<!--.+-->\\n/, ''\n end\nend\n" |
#customize_resource_controller_for_devise(adding_first_and_last_name) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/voyage/app_builder.rb', line 294 def customize_resource_controller_for_devise(adding_first_and_last_name) bundle_command 'exec rails generate controller users' run 'rm spec/controllers/users_controller_spec.rb' inject_into_class 'app/controllers/users_controller.rb', 'UsersController' do " # https://github.com/CanCanCommunity/cancancan/wiki/authorizing-controller-actions\n # load_and_authorize_resource only: []\n skip_authorization_check only: [:analytics_alias]\n\n def analytics_alias\n # view file has JS that will identify the anonymous user through segment\n # after registration via \"after devise registration path\"\n end\n RUBY\n end\nend\n".gsub(/^ {6}/, '') |
#customize_user_factory(adding_first_and_last_name) ⇒ Object
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/voyage/app_builder.rb', line 455 def customize_user_factory(adding_first_and_last_name) inject_into_file 'spec/factories/users.rb', before: /^ end/ do " password 'asdfjkl123'\n password_confirmation 'asdfjkl123'\n sequence(:email) { |n| \"user_\#{n}@example.com\" }\n\n trait :admin do\n roles [:admin]\n email '[email protected]'\n end\n RUBY\n end\n\n if adding_first_and_last_name\n inject_into_file 'spec/factories/users.rb', after: /roles \\[:admin\\]\\n/ do <<-'RUBY'.gsub(/^ {4}/, '')\n first_name 'Admin'\n last_name 'User'\n RUBY\n end\n end\nend\n".gsub(/^ {4}/, '') |
#customize_user_spec ⇒ Object
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/voyage/app_builder.rb', line 486 def customize_user_spec find = " pending \"add some examples to (or delete) \\\#{__FILE__}\"\n RUBY\n\n replace = <<-RUBY.gsub(/^ {6}/, '')\n describe 'constants' do\n context 'roles' do\n it 'has the admin role' do\n expect(User::ROLES).to eq([:admin])\n end\n end\n end\n\n describe 'validations' do\n it { is_expected.to validate_presence_of(:email) }\n it { is_expected.to validate_presence_of(:password) }\n it { is_expected.to validate_presence_of(:password_confirmation) }\n end\n\n context '#tester?' do\n ['example.com', 'headway.io'].each do |domain|\n it \"an email including the \\\#{domain} domain is a tester\" do\n user = build(:user, email: \"asdf@\\\#{domain}\")\n expect(user.tester?).to eq(true)\n end\n end\n\n it 'an email including the gmail.com domain is NOT a tester' do\n user = build(:user, email: '[email protected]')\n expect(user.tester?).to eq(false)\n end\n end\n\n context 'new user creation' do\n it 'ensures uniqueness of the uuid' do\n allow(User).to receive(:exists?).and_return(true, false)\n\n expect do\n create(:user)\n end.to change { User.count }.by(1)\n\n expect(User).to have_received(:exists?).exactly(2).times\n end\n end\n RUBY\n\n replace_in_file 'spec/models/user_spec.rb', find, replace\nend\n".gsub(/^ {6}/, '') |
#disallow_wrapping_parameters ⇒ Object
194 195 196 |
# File 'lib/suspenders/app_builder.rb', line 194 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#downgrade_neat_1_8_so_refills_media_mixin_works ⇒ Object
TEMP FIX
https://github.com/thoughtbot/bourbon/issues/993
https://github.com/thoughtbot/refills/issues/400
633 634 635 636 637 |
# File 'lib/voyage/app_builder.rb', line 633 def downgrade_neat_1_8_so_refills_media_mixin_works replace_in_file 'Gemfile', "gem 'neat', '~> 2.0.0.beta.1'", "gem 'neat', '~> 1.8.0'" run 'gem uninstall -x neat -v2.0.0' run 'bundle' end |
#enable_database_cleaner ⇒ Object
247 248 249 |
# File 'lib/suspenders/app_builder.rb', line 247 def enable_database_cleaner copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_rack_canonical_host ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/suspenders/app_builder.rb', line 151 def enable_rack_canonical_host config = "\n if ENV.fetch(\"HEROKU_APP_NAME\", \"\").include?(\"staging-pr-\")\nENV[\"APPLICATION_HOST\"] = ENV[\"HEROKU_APP_NAME\"] + \".herokuapp.com\"\n end\n\n config.middleware.use Rack::CanonicalHost, ENV.fetch(\"APPLICATION_HOST\")\n RUBY\n\n inject_into_file(\n \"config/environments/production.rb\",\n config,\n after: \"Rails.application.configure do\",\n )\nend\n" |
#enable_rack_deflater ⇒ Object
168 169 170 |
# File 'lib/suspenders/app_builder.rb', line 168 def enable_rack_deflater configure_environment "production", "config.middleware.use Rack::Deflater" end |
#gemfile ⇒ Object
27 28 29 |
# File 'lib/suspenders/app_builder.rb', line 27 def gemfile template "Gemfile.erb", "Gemfile" end |
#generate_data_migrations ⇒ Object
601 602 603 604 605 606 607 608 |
# File 'lib/voyage/app_builder.rb', line 601 def generate_data_migrations generate 'data_migrations:install' file = Dir['db/migrate/*_create_data_migrations.rb'].first replace_in_file file, 'class CreateDataMigrations < ActiveRecord::Migration', "class CreateDataMigrations < ActiveRecord::Migration[4.2]" empty_directory_with_keep_file 'db/data_migrate' end |
#generate_factories_file ⇒ Object
setup_test_environment overrides
880 881 882 |
# File 'lib/voyage/app_builder.rb', line 880 def generate_factories_file # NOTE: (2016-02-03) jonk => don't want this, we use individual factories end |
#generate_refills ⇒ Object
ADDING REFILLS COMPONENTS
646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/voyage/app_builder.rb', line 646 def generate_refills if @@accept_defaults || agree?('Would you like to install default Refill components? (Y/n)') @@add_refills = true bundle_command 'exec rails generate refills:import navigation' bundle_command 'exec rails generate refills:import footer' add_refills_to_stylesheets else @@add_refills = false end end |
#generate_rspec ⇒ Object
325 326 327 |
# File 'lib/suspenders/app_builder.rb', line 325 def generate_rspec generate 'rspec:install' end |
#generate_ruby_version_and_gemset ⇒ Object
597 598 599 |
# File 'lib/voyage/app_builder.rb', line 597 def generate_ruby_version_and_gemset create_file '.ruby-gemset', "#{app_name}\n" end |
#generate_seeder_templates(using_devise:) ⇒ Object
END DEVISE SETUP
480 481 482 483 484 |
# File 'lib/voyage/app_builder.rb', line 480 def generate_seeder_templates(using_devise:) config = { force: true, using_devise: using_devise } template '../templates/seeder.rb.erb', 'lib/seeder.rb', config template '../templates/seeds.rb.erb', 'db/seeds.rb', config end |
#generate_test_environment ⇒ Object
END ADDING REFILLS COMPONENTS
732 733 734 735 |
# File 'lib/voyage/app_builder.rb', line 732 def generate_test_environment template '../templates/controller_helpers.rb', 'spec/support/controller_helpers.rb' template '../templates/simplecov.rb', '.simplecov' end |
#gitignore ⇒ Object
23 24 25 |
# File 'lib/suspenders/app_builder.rb', line 23 def gitignore copy_file "suspenders_gitignore", ".gitignore" end |
#init_git ⇒ Object
355 356 357 |
# File 'lib/suspenders/app_builder.rb', line 355 def init_git run 'git init' end |
#install_devise ⇒ Object
DEVISE SETUP
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/voyage/app_builder.rb', line 86 def install_devise if @@accept_defaults || agree?('Would you like to install Devise? (Y/n)') @@use_devise = true if @@accept_defaults || agree?('Would you like to install Devise token authentication? (Y/n)') devise_token_auth = true end bundle_command 'exec rails generate devise:install' if @@accept_defaults || agree?("Would you like to add first_name and last_name to the devise model? (Y/n)") adding_first_and_last_name = true bundle_command "exec rails generate resource user first_name:string last_name:string uuid:string" replace_in_file 'spec/factories/users.rb', 'first_name "MyString"', 'first_name { Faker::Name.first_name }' replace_in_file 'spec/factories/users.rb', 'last_name "MyString"', 'last_name { Faker::Name.last_name }' replace_in_file 'spec/factories/users.rb', 'uuid "MyString"', 'uuid { SecureRandom.uuid }' end bundle_command "exec rails generate devise user" bundle_command 'exec rails generate devise:views' if @@use_slim inside('lib') do # arbitrary, run in context of newly generated app run "erb2slim '../app/views/devise' '../app/views/devise'" run "erb2slim -d '../app/views/devise'" end end customize_devise_views if adding_first_and_last_name customize_application_controller_for_devise(adding_first_and_last_name, devise_token_auth) add_devise_registrations_controller customize_resource_controller_for_devise(adding_first_and_last_name) add_admin_views_for_devise_resource(adding_first_and_last_name) add_analytics_initializer add_canard_roles_to_devise_resource update_devise_initializer add_custom_routes_for_devise customize_user_factory(adding_first_and_last_name) generate_seeder_templates(using_devise: true) customize_user_spec add_token_auth else generate_seeder_templates(using_devise: false) end end |
#overwrite_application_layout ⇒ Object
865 866 867 868 869 870 |
# File 'lib/voyage/app_builder.rb', line 865 def overwrite_application_layout template '../templates/voyage_layout.html.erb.erb', 'app/views/layouts/application.html.erb', force: true, add_refills: @@add_refills update_application_layout_for_slim if @@use_slim template '../templates/analytics_identify.html.erb.erb', 'app/views/application/_analytics_identify.html.erb', force: true end |
#provide_dev_prime_task ⇒ Object
101 102 103 |
# File 'lib/suspenders/app_builder.rb', line 101 def provide_dev_prime_task copy_file 'dev.rake', 'lib/tasks/dev.rake' end |
#provide_setup_script ⇒ Object
96 97 98 99 |
# File 'lib/suspenders/app_builder.rb', line 96 def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end |
#provide_shoulda_matchers_config ⇒ Object
251 252 253 254 255 256 |
# File 'lib/suspenders/app_builder.rb', line 251 def provide_shoulda_matchers_config copy_file( "shoulda_matchers_config_rspec.rb", "spec/support/shoulda_matchers.rb" ) end |
#raise_on_delivery_errors ⇒ Object
42 43 44 45 |
# File 'lib/suspenders/app_builder.rb', line 42 def raise_on_delivery_errors replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true' end |
#raise_on_missing_assets_in_test ⇒ Object
38 39 40 |
# File 'lib/suspenders/app_builder.rb', line 38 def raise_on_missing_assets_in_test configure_environment "test", "config.assets.raise_runtime_errors = true" end |
#raise_on_unpermitted_parameters ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/suspenders/app_builder.rb', line 80 def raise_on_unpermitted_parameters config = "config.action_controller.action_on_unpermitted_parameters = :raise\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n" |
#rake_db_setup ⇒ Object
Do this last
792 793 794 795 |
# File 'lib/voyage/app_builder.rb', line 792 def rake_db_setup rake 'db:migrate' rake 'db:seed' if File.exist?('config/initializers/devise.rb') end |
#readme ⇒ Object
19 20 21 |
# File 'lib/suspenders/app_builder.rb', line 19 def readme template 'README.md.erb', 'README.md' end |
#remove_config_comment_lines ⇒ Object
End setup_test_environment overrides
901 902 903 |
# File 'lib/voyage/app_builder.rb', line 901 def remove_config_comment_lines # NOTE: (2016-02-09) jonk => don't want this end |
#remove_routes_comment_lines ⇒ Object
453 454 455 456 457 |
# File 'lib/suspenders/app_builder.rb', line 453 def remove_routes_comment_lines replace_in_file 'config/routes.rb', /Rails\.application\.routes\.draw do.*end/m, "Rails.application.routes.draw do\nend" end |
#remove_turbolinks ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/suspenders/app_builder.rb', line 47 def remove_turbolinks replace_in_file( "app/assets/javascripts/application.js", "//= require turbolinks", "" ) end |
#replace_default_puma_configuration ⇒ Object
329 330 331 |
# File 'lib/suspenders/app_builder.rb', line 329 def replace_default_puma_configuration copy_file "puma.rb", "config/puma.rb", force: true end |
#replace_gemfile(path) ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/suspenders/app_builder.rb', line 233 def replace_gemfile(path) template 'Gemfile.erb', 'Gemfile', force: true do |content| if path content.gsub(%r{gem .suspenders.}) { |s| %{#{s}, path: "#{path}"} } else content end end end |
#require_files_in_lib ⇒ Object
588 589 590 591 592 593 594 595 |
# File 'lib/voyage/app_builder.rb', line 588 def require_files_in_lib create_file 'config/initializers/require_files_in_lib.rb' do " # rubocop:disable Rails/FilePath\n Dir[File.join(Rails.root, 'lib', '**', '*.rb')].each { |l| require l }\n # rubocop:enable Rails/FilePath\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#run_rubocop_auto_correct ⇒ Object
814 815 816 |
# File 'lib/voyage/app_builder.rb', line 814 def run_rubocop_auto_correct run 'rubocop --auto-correct' end |
#set_ruby_to_version_being_used ⇒ Object
861 862 863 |
# File 'lib/voyage/app_builder.rb', line 861 def set_ruby_to_version_being_used create_file '.ruby-version', "#{Voyage::RUBY_VERSION}\n" end |
#set_test_delivery_method ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/suspenders/app_builder.rb', line 55 def set_test_delivery_method inject_into_file( "config/environments/development.rb", "\n config.action_mailer.delivery_method = :file", after: "config.action_mailer.raise_delivery_errors = true", ) end |
#set_up_factory_girl_for_rspec ⇒ Object
123 124 125 |
# File 'lib/suspenders/app_builder.rb', line 123 def set_up_factory_girl_for_rspec copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb' end |
#set_up_forego ⇒ Object
333 334 335 |
# File 'lib/suspenders/app_builder.rb', line 333 def set_up_forego copy_file "Procfile", "Procfile" end |
#set_up_hound ⇒ Object
131 132 133 |
# File 'lib/suspenders/app_builder.rb', line 131 def set_up_hound copy_file "hound.yml", ".hound.yml" end |
#setup_asset_host ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/suspenders/app_builder.rb', line 172 def setup_asset_host replace_in_file 'config/environments/production.rb', "# config.action_controller.asset_host = 'http://assets.example.com'", 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))' replace_in_file 'config/initializers/assets.rb', "config.assets.version = '1.0'", 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")' config = "config.public_file_server.headers = {\n\"Cache-Control\" => \"public, max-age=31557600\",\n }\n EOD\n\n configure_environment(\"production\", config)\nend\n" |
#setup_bundler_audit ⇒ Object
403 404 405 406 |
# File 'lib/suspenders/app_builder.rb', line 403 def setup_bundler_audit copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake" append_file "Rakefile", %{\ntask default: "bundle:audit"\n} end |
#setup_default_directories ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/suspenders/app_builder.rb', line 337 def setup_default_directories [ 'app/views/pages', 'spec/lib', 'spec/controllers', 'spec/helpers', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| empty_directory_with_keep_file dir end end |
#setup_default_rake_task ⇒ Object
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/suspenders/app_builder.rb', line 459 def setup_default_rake_task append_file 'Rakefile' do "task(:default).clear\ntask default: [:spec]\n\nif defined? RSpec\n task(:spec).clear\n RSpec::Core::RakeTask.new(:spec) do |t|\nt.verbose = false\n end\nend\n EOS\n end\nend\n" |
#setup_rack_mini_profiler ⇒ Object
31 32 33 34 35 36 |
# File 'lib/suspenders/app_builder.rb', line 31 def setup_rack_mini_profiler copy_file( "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb", ) end |
#setup_secret_token ⇒ Object
190 191 192 |
# File 'lib/suspenders/app_builder.rb', line 190 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#setup_segment ⇒ Object
398 399 400 401 |
# File 'lib/suspenders/app_builder.rb', line 398 def setup_segment copy_file '_analytics.html.erb', 'app/views/application/_analytics.html.erb' end |
#setup_spring ⇒ Object
408 409 410 |
# File 'lib/suspenders/app_builder.rb', line 408 def setup_spring bundle_command "exec spring binstub --all" end |
#spin_up_webpacker ⇒ Object
834 835 836 837 |
# File 'lib/voyage/app_builder.rb', line 834 def spin_up_webpacker rake 'webpacker:install' rake 'webpacker:install:react' end |
#update_application_css_file ⇒ Object
688 689 690 691 692 693 694 695 696 |
# File 'lib/voyage/app_builder.rb', line 688 def update_application_css_file inject_into_file 'app/assets/stylesheets/application.scss', before: '@import "neat";' do " $visual-grid: true;\n $visual-grid-color: #9cf !default;\n $visual-grid-index: front !default;\n $visual-grid-opacity: 0.1 !default;\n RUBY\n end\nend\n".gsub(/^ {8}/, '') |
#update_application_layout_for_slim ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/voyage/app_builder.rb', line 36 def update_application_layout_for_slim find = " <%#\n Configure default and controller-, and view-specific titles in\n config/locales/en.yml. For more see:\n https://github.com/calebthompson/title#usage\n %>\n RUBY\n\n replace = <<-RUBY.gsub(/^ {8}/, '')\n <% # Configure default and controller-, and view-specific titles in\n # config/locales/en.yml. For more see:\n # https://github.com/calebthompson/title#usage %>\n RUBY\n\n replace_in_file 'app/views/layouts/application.html.erb', find, replace\n\n inside('lib') do # arbitrary, run in context of newly generated app\n run \"erb2slim '../app/views/layouts' '../app/views/layouts'\"\n run \"erb2slim -d '../app/views/layouts'\"\n end\n\n # strip trailing space after closing \"> in application layout before\n # trying to find and replace it\n replace_in_file 'app/views/layouts/application.html.slim', '| \"> ', '| \">'\n\n find = <<-RUBY.gsub(/^ {6}/, '')\n | <body class=\"\n = devise_controller? ? 'devise' : 'application'\n = body_class\n | \">\n RUBY\n\n replace = <<-RUBY.gsub(/^ {6}/, '')\n body class=\"\\\#{devise_controller? ? 'devise' : 'application'} \\\#{body_class}\"\n RUBY\n\n replace_in_file 'app/views/layouts/application.html.slim', find, replace\nend\n".gsub(/^ {4}/, '') |
#update_application_rb_for_slim ⇒ Object
76 77 78 79 80 81 |
# File 'lib/voyage/app_builder.rb', line 76 def update_application_rb_for_slim inject_into_file "config/application.rb", after: " g.fixture_replacement :factory_girl, dir: 'spec/factories'\n" do " g.template_engine :slim\n RUBY\n end\nend\n".gsub(/^ {2}/, '') |
#update_delayed_job_migration_rails_5_1_specify_4_2 ⇒ Object
768 769 770 771 |
# File 'lib/voyage/app_builder.rb', line 768 def update_delayed_job_migration_rails_5_1_specify_4_2 file = Dir['db/migrate/*_create_delayed_jobs.rb'].first replace_in_file file, 'class CreateDelayedJobs < ActiveRecord::Migration', "class CreateDelayedJobs < ActiveRecord::Migration[4.2]" end |
#update_devise_initializer ⇒ Object
403 404 405 406 407 408 409 410 |
# File 'lib/voyage/app_builder.rb', line 403 def update_devise_initializer replace_in_file 'config/initializers/devise.rb', 'config.sign_out_via = :delete', 'config.sign_out_via = :get' replace_in_file 'config/initializers/devise.rb', "config.mailer_sender = '[email protected]'", "config.mailer_sender = '[email protected]'" end |
#update_flashes_css_file ⇒ Object
684 685 686 |
# File 'lib/voyage/app_builder.rb', line 684 def update_flashes_css_file replace_in_file 'app/assets/stylesheets/refills/_flashes.scss', "margin-bottom: $base-spacing / 2;", "// margin-bottom: $base-spacing / 2;" end |
#update_gemset_in_gemfile ⇒ Object
18 19 20 21 22 23 |
# File 'lib/voyage/app_builder.rb', line 18 def update_gemset_in_gemfile replace_in_file 'Gemfile', '#ruby-gemset', "#ruby-gemset=#{app_name}" # Remove commented out lines from template gsub_file('Gemfile', /^\s{2}\n/, '') end |
#update_test_environment ⇒ Object
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/voyage/app_builder.rb', line 737 def update_test_environment inject_into_file 'spec/support/factory_girl.rb', before: /^end/ do "\n # Spring doesn't reload factory_girl\n config.before(:all) do\n FactoryGirl.reload\n end\n RUBY\n end\n\n template \"../templates/rails_helper.rb.erb\", \"spec/rails_helper.rb\", force: true\n\n %w(test development).each do |environment|\n inject_into_file \"config/environments/\#{environment}.rb\", after: /^end/ do <<-RUBY.gsub(/^ {10}/, '')\n\n # NOTE: console can use create(:factory_name), or build(:factory_name) without\n # needing to use FactoryGirl.create(:factory_name).\n include FactoryGirl::Syntax::Methods\n RUBY\n end\n end\nend\n".gsub(/^ {6}/, '') |
#use_postgres_config_template ⇒ Object
224 225 226 227 |
# File 'lib/suspenders/app_builder.rb', line 224 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |
#use_slim ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/voyage/app_builder.rb', line 25 def use_slim if @@accept_defaults || agree?('Would you like to use slim? (Y/n)') @@use_slim = true run 'gem install html2slim' update_application_rb_for_slim else @@use_slim = false gsub_file('Gemfile', /^gem 'slim-rails'\n/, '') end end |