Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #add_webpacker ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_active_job ⇒ Object
- #configure_airbrake ⇒ Object
- #configure_generators ⇒ Object
- #configure_heroku_app(environment) ⇒ Object
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_i18n_for_test_environment ⇒ Object
- #configure_i18n_tasks ⇒ Object
- #configure_lib_directory ⇒ Object
- #configure_newrelic ⇒ Object
- #configure_production_log_level ⇒ Object
- #configure_puma ⇒ Object
- #configure_quiet_assets ⇒ Object
- #configure_rspec ⇒ Object
- #configure_rubocop ⇒ Object
- #configure_simple_form ⇒ Object
- #configure_smtp ⇒ Object
- #configure_spec_support_features ⇒ Object
- #configure_time_formats ⇒ Object
- #copy_env_example ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_database ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_initial_commit ⇒ Object
- #create_partials_directory ⇒ Object
- #create_production_heroku_app(flags) ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #create_staging_heroku_app(flags) ⇒ Object
- #customize_error_pages ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_rack_canonical_host ⇒ Object
- #enable_rack_deflater ⇒ Object
- #fix_i18n_deprecation_warning ⇒ Object
- #generate_rspec ⇒ Object
- #generate_secret ⇒ Object
- #gitignore_files ⇒ Object
- #init_git ⇒ Object
- #inject_webpacker_into_layout ⇒ Object
- #inject_webpacker_into_setup ⇒ Object
- #install_bootstrap ⇒ Object
- #install_bourbon_n_friends ⇒ Object
- #install_foundation ⇒ Object
- #provide_setup_script ⇒ Object
- #pull_request_template ⇒ Object
- #raise_on_delivery_errors ⇒ Object
- #raise_on_unpermitted_parameters ⇒ Object
- #readme ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #replace_gemfile ⇒ Object
- #run_autofixes ⇒ Object
- #run_bin_setup ⇒ Object
- #run_webpacker_install ⇒ Object
- #set_heroku_rails_secrets ⇒ Object
- #set_heroku_serve_static_files ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #set_test_delivery_method ⇒ Object
- #setup_and_push_to_origin_remote(remote_url) ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_bundler_audit ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_deployment_environment_branches ⇒ Object
- #setup_foreman ⇒ Object
- #setup_heroku_specific_gems ⇒ Object
- #setup_javascripts ⇒ Object
- #setup_secret_token ⇒ Object
- #setup_segment ⇒ Object
- #setup_spring ⇒ Object
- #setup_staging_environment ⇒ Object
- #setup_stylesheets ⇒ Object
- #use_postgres_config_template ⇒ Object
- #version_gems_in_gemfile ⇒ Object
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#add_webpacker ⇒ Object
218 219 220 221 222 223 224 |
# File 'lib/suspenders/app_builder.rb', line 218 def add_webpacker inject_into_file( "Gemfile", %{\ngem "webpacker"}, after: /gem "puma"/ ) end |
#configure_action_mailer ⇒ Object
282 283 284 285 286 287 |
# File 'lib/suspenders/app_builder.rb', line 282 def configure_action_mailer action_mailer_host "development", %{ENV["HOST"] || "localhost:3000"} action_mailer_host "test", %{"www.example.com"} action_mailer_host "staging", %{ENV.fetch("HOST")} action_mailer_host "production", %{ENV.fetch("HOST")} end |
#configure_action_mailer_in_specs ⇒ Object
269 270 271 |
# File 'lib/suspenders/app_builder.rb', line 269 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_active_job ⇒ Object
289 290 291 292 293 294 |
# File 'lib/suspenders/app_builder.rb', line 289 def configure_active_job configure_application_file( "config.active_job.queue_adapter = :sidekiq" ) configure_environment "test", "config.active_job.queue_adapter = :inline" end |
#configure_airbrake ⇒ Object
597 598 599 |
# File 'lib/suspenders/app_builder.rb', line 597 def configure_airbrake template 'airbrake.rb', 'config/initializers/airbrake.rb' end |
#configure_generators ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/suspenders/app_builder.rb', line 39 def configure_generators config = <<-RUBY config.generators do |generate| generate.helper false generate.javascript_engine false generate.request_specs false generate.routing_specs false generate.stylesheets false generate.test_framework :rspec generate.view_specs false end RUBY inject_into_class 'config/application.rb', 'Application', config end |
#configure_heroku_app(environment) ⇒ Object
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 |
# File 'lib/suspenders/app_builder.rb', line 496 def configure_heroku_app(environment) run_heroku "addons:create sendgrid", environment run_heroku "addons:create airbrake:hrk-free-2018", environment run_heroku "addons:create papertrail", environment run_heroku "addons:create heroku-postgresql:hobby-dev", environment run_heroku "addons:create newrelic:wayne", environment run_heroku "addons:create heroku-redis:hobby-dev", environment if environment == 'production' run_heroku "pg:backups schedule DATABASE_URL "\ "--at '02:00 America/Los_Angeles'", environment end domain = "#{heroku_app_name_for(environment)}.herokuapp.com" env_vars = [ 'SMTP_DOMAIN=heroku.com', 'SMTP_ADDRESS=smtp.sendgrid.net', 'SMTP_PROVIDER=sendgrid', "HOST=#{domain}", "ASSET_HOST=//#{domain}" ] run_heroku "config:add #{env_vars.join(' ')}", environment end |
#configure_i18n_for_missing_translations ⇒ Object
259 260 261 262 |
# File 'lib/suspenders/app_builder.rb', line 259 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
255 256 257 |
# File 'lib/suspenders/app_builder.rb', line 255 def configure_i18n_for_test_environment copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_i18n_tasks ⇒ Object
264 265 266 267 |
# File 'lib/suspenders/app_builder.rb', line 264 def configure_i18n_tasks run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/" copy_file "config_i18n_tasks.yml", "config/i18n-tasks.yml" end |
#configure_lib_directory ⇒ Object
619 620 621 622 623 624 625 626 |
# File 'lib/suspenders/app_builder.rb', line 619 def configure_lib_directory config = <<-RUBY config.autoload_paths << Rails.root.join('lib') config.eager_load_paths << Rails.root.join('lib') RUBY inject_into_class "config/application.rb", "Application", config end |
#configure_newrelic ⇒ Object
57 58 59 |
# File 'lib/suspenders/app_builder.rb', line 57 def configure_newrelic template 'newrelic.yml.erb', 'config/newrelic.yml' end |
#configure_production_log_level ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/suspenders/app_builder.rb', line 91 def configure_production_log_level replace_in_file( 'config/environments/production.rb', " # Use the lowest log level to ensure availability of diagnostic information\n # when problems arise.", '' ) replace_in_file( 'config/environments/production.rb', ' config.log_level = :debug', ' config.log_level = :info' ) end |
#configure_puma ⇒ Object
308 309 310 |
# File 'lib/suspenders/app_builder.rb', line 308 def configure_puma copy_file 'puma.rb', 'config/puma.rb', force: true end |
#configure_quiet_assets ⇒ Object
611 612 613 614 615 616 617 |
# File 'lib/suspenders/app_builder.rb', line 611 def configure_quiet_assets config = <<-RUBY config.assets.quiet = true RUBY inject_into_class "config/application.rb", "Application", config end |
#configure_rspec ⇒ Object
247 248 249 250 251 252 253 |
# File 'lib/suspenders/app_builder.rb', line 247 def configure_rspec remove_file '.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_rubocop ⇒ Object
593 594 595 |
# File 'lib/suspenders/app_builder.rb', line 593 def configure_rubocop template '.rubocop.yml', '.rubocop.yml' end |
#configure_simple_form ⇒ Object
278 279 280 |
# File 'lib/suspenders/app_builder.rb', line 278 def configure_simple_form bundle_command "exec rails generate simple_form:install" end |
#configure_smtp ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/suspenders/app_builder.rb', line 61 def configure_smtp copy_file 'smtp.rb', 'config/smtp.rb' prepend_file 'config/environments/production.rb', %{require Rails.root.join("config/smtp")\n} config = <<-RUBY config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = SMTP_SETTINGS RUBY inject_into_file 'config/environments/production.rb', config, :after => 'config.action_mailer.raise_delivery_errors = false' end |
#configure_spec_support_features ⇒ Object
242 243 244 245 |
# File 'lib/suspenders/app_builder.rb', line 242 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
273 274 275 276 |
# File 'lib/suspenders/app_builder.rb', line 273 def configure_time_formats remove_file "config/locales/en.yml" template "config_locales_en.yml.erb", "config/locales/en.yml" end |
#copy_env_example ⇒ Object
601 602 603 604 |
# File 'lib/suspenders/app_builder.rb', line 601 def copy_env_example template ".env.example", ".env.example" append_file ".env.example", "SECRET_KEY_BASE=#{generate_secret}" end |
#copy_miscellaneous_files ⇒ Object
552 553 554 555 |
# File 'lib/suspenders/app_builder.rb', line 552 def copy_miscellaneous_files copy_file "errors.rb", "config/initializers/errors.rb" copy_file "json_encoding.rb", "config/initializers/json_encoding.rb" end |
#create_application_layout ⇒ Object
170 171 172 173 174 |
# File 'lib/suspenders/app_builder.rb', line 170 def create_application_layout template 'suspenders_layout.html.erb.erb', 'app/views/layouts/application.html.erb', force: true end |
#create_database ⇒ Object
181 182 183 |
# File 'lib/suspenders/app_builder.rb', line 181 def create_database bundle_command 'exec rake db:create db:migrate' end |
#create_github_repo(repo_name) ⇒ Object
534 535 536 537 |
# File 'lib/suspenders/app_builder.rb', line 534 def create_github_repo(repo_name) path_addition = override_path_for_tests run "#{path_addition} hub create #{repo_name} -p" end |
#create_heroku_apps(flags) ⇒ Object
491 492 493 494 |
# File 'lib/suspenders/app_builder.rb', line 491 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_initial_commit ⇒ Object
465 466 467 468 |
# File 'lib/suspenders/app_builder.rb', line 465 def create_initial_commit run 'git add -A' run 'git commit -m "Initial app setup." --no-verify' end |
#create_partials_directory ⇒ Object
157 158 159 |
# File 'lib/suspenders/app_builder.rb', line 157 def create_partials_directory empty_directory 'app/views/application' end |
#create_production_heroku_app(flags) ⇒ Object
484 485 486 487 488 489 |
# File 'lib/suspenders/app_builder.rb', line 484 def create_production_heroku_app(flags) app_name = heroku_app_name_for("production") run_heroku "create #{app_name} #{flags}", "production" configure_heroku_app("production") end |
#create_shared_flashes ⇒ Object
161 162 163 164 |
# File 'lib/suspenders/app_builder.rb', line 161 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
166 167 168 |
# File 'lib/suspenders/app_builder.rb', line 166 def create_shared_javascripts copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb' end |
#create_staging_heroku_app(flags) ⇒ Object
475 476 477 478 479 480 481 482 |
# File 'lib/suspenders/app_builder.rb', line 475 def create_staging_heroku_app(flags) rack_env = "RACK_ENV=staging RAILS_ENV=staging" app_name = heroku_app_name_for("staging") run_heroku "create #{app_name} #{flags}", "staging" run_heroku "config:add #{rack_env}", "staging" configure_heroku_app("staging") end |
#customize_error_pages ⇒ Object
557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/suspenders/app_builder.rb', line 557 def customize_error_pages =<<-EOS <meta charset="utf-8" /> <meta name="ROBOTS" content="NOODP" /> <meta name="viewport" content="initial-scale=1" /> EOS %w(500 404 422).each do |page| inject_into_file "public/#{page}.html", , :after => "<head>\n" replace_in_file "public/#{page}.html", /<!--.+-->\n/, '' end end |
#disallow_wrapping_parameters ⇒ Object
153 154 155 |
# File 'lib/suspenders/app_builder.rb', line 153 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#enable_database_cleaner ⇒ Object
238 239 240 |
# File 'lib/suspenders/app_builder.rb', line 238 def enable_database_cleaner copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_rack_canonical_host ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/suspenders/app_builder.rb', line 77 def enable_rack_canonical_host config = <<-RUBY # Ensure requests are only served from one, canonical host name config.middleware.use Rack::CanonicalHost, ENV.fetch("HOST") RUBY inject_into_file( "config/environments/production.rb", config, after: serve_static_files_line ) end |
#enable_rack_deflater ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/suspenders/app_builder.rb', line 105 def enable_rack_deflater config = <<-RUBY # Enable deflate / gzip compression of controller-generated responses config.middleware.use Rack::Deflater RUBY inject_into_file( "config/environments/production.rb", config, after: serve_static_files_line ) end |
#fix_i18n_deprecation_warning ⇒ Object
296 297 298 299 300 301 302 |
# File 'lib/suspenders/app_builder.rb', line 296 def fix_i18n_deprecation_warning config = <<-RUBY config.i18n.enforce_available_locales = true RUBY inject_into_class 'config/application.rb', 'Application', config end |
#generate_rspec ⇒ Object
304 305 306 |
# File 'lib/suspenders/app_builder.rb', line 304 def generate_rspec generate 'rspec:install' end |
#generate_secret ⇒ Object
628 629 630 |
# File 'lib/suspenders/app_builder.rb', line 628 def generate_secret SecureRandom.hex(64) end |
#gitignore_files ⇒ Object
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/suspenders/app_builder.rb', line 430 def gitignore_files remove_file '.gitignore' copy_file 'suspenders_gitignore', '.gitignore' [ 'app/workers', 'spec/lib', 'spec/controllers', 'spec/helpers', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| create_empty_directory(dir) end end |
#init_git ⇒ Object
446 447 448 449 450 451 452 |
# File 'lib/suspenders/app_builder.rb', line 446 def init_git run 'git init' template '.overcommit.yml', '.overcommit.yml' bundle_command 'exec overcommit --install' bundle_command 'exec overcommit --sign' bundle_command 'exec overcommit --sign pre-commit' end |
#inject_webpacker_into_layout ⇒ Object
328 329 330 331 332 333 334 |
# File 'lib/suspenders/app_builder.rb', line 328 def inject_webpacker_into_layout gsub_file( 'app/views/application/_javascript.html.erb', Regexp.new("<%= javascript_include_tag :application %>"), %{\n<%= javascript_pack_tag 'application' %>\n<%= stylesheet_pack_tag 'application' %>} ) end |
#inject_webpacker_into_setup ⇒ Object
336 337 338 339 340 341 342 |
# File 'lib/suspenders/app_builder.rb', line 336 def inject_webpacker_into_setup inject_into_file( 'bin/setup', %{\nsystem! 'npm install -g yarn'\nsystem! 'yarn install'\n}, after: /# Install JavaScript dependencies if using Yarn/ ) end |
#install_bootstrap ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/suspenders/app_builder.rb', line 364 def install_bootstrap inject_into_file( 'Gemfile', %{\ngem 'bootstrap-sass'}, after: /gem 'sass-rails',.*$/ ) bundle_command 'install' inject_into_file( 'app/assets/stylesheets/application.scss', %{\n@import "bootstrap-sprockets";\n@import "bootstrap";}, after: /@charset "utf-8";/ ) inject_into_file( 'app/assets/javascripts/application.js', %{\n\/\/= require bootstrap-sprockets}, after: /\/\/= require jquery-ujs/ ) end |
#install_bourbon_n_friends ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/suspenders/app_builder.rb', line 344 def install_bourbon_n_friends inject_into_file( 'Gemfile', %{\ngem 'bourbon'\ngem 'neat'}, after: Regexp.new("gem 'rails', '#{Suspenders::RAILS_VERSION}'") ) bundle_command 'install' inject_into_file( 'app/assets/stylesheets/application.scss', %{ @import "bourbon"; @import "neat"; @import "base/grid-settings"; @import "base/base"; }, after: /@charset "utf-8";/ ) end |
#install_foundation ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/suspenders/app_builder.rb', line 385 def install_foundation inject_into_file( 'Gemfile', %{\ngem 'foundation-rails'}, after: /gem 'sass-rails',.*$/ ) inject_into_file( 'app/assets/stylesheets/application.scss', %{\n@import "foundation_and_overrides";}, after: /@charset "utf-8";/ ) inject_into_file( 'app/assets/javascripts/application.js', %{\n\/\/= require foundation}, after: /\/\/= require jquery-ujs/ ) inject_into_file( 'app/assets/javascripts/application.js', %{\n$(document).foundation();}, after: /\/\/= require_tree ./ ) inject_into_file( 'app/views/layouts/application.html.erb', %{<%= javascript_include_tag "vendor/modernizr" %>\n}, before: /<title>.*$/ ) bundle_command 'install' result = run('bundle show foundation-rails', capture: true ).gsub("\n",'') settings_file = File.join( result, 'vendor', 'assets', 'stylesheets', 'foundation', '_settings.scss' ) create_file( "app/assets/stylesheets/foundation_and_overrides.scss", File.read(settings_file) ) end |
#provide_setup_script ⇒ Object
34 35 36 37 |
# File 'lib/suspenders/app_builder.rb', line 34 def provide_setup_script run "rm bin/setup" template "setup.rb", "bin/setup" end |
#pull_request_template ⇒ Object
9 10 11 |
# File 'lib/suspenders/app_builder.rb', line 9 def pull_request_template template 'PULL_REQUEST_TEMPLATE.md.erb', 'PULL_REQUEST_TEMPLATE.md' end |
#raise_on_delivery_errors ⇒ Object
13 14 15 16 |
# File 'lib/suspenders/app_builder.rb', line 13 def raise_on_delivery_errors replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true' end |
#raise_on_unpermitted_parameters ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/suspenders/app_builder.rb', line 26 def raise_on_unpermitted_parameters config = <<-RUBY config.action_controller.action_on_unpermitted_parameters = :raise RUBY inject_into_class "config/application.rb", "Application", config end |
#readme ⇒ Object
5 6 7 |
# File 'lib/suspenders/app_builder.rb', line 5 def readme template 'README.md.erb', 'README.md' end |
#remove_routes_comment_lines ⇒ Object
570 571 572 573 574 |
# File 'lib/suspenders/app_builder.rb', line 570 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 |
#replace_gemfile ⇒ Object
185 186 187 188 |
# File 'lib/suspenders/app_builder.rb', line 185 def replace_gemfile remove_file 'Gemfile' template 'Gemfile.erb', 'Gemfile' end |
#run_autofixes ⇒ Object
459 460 461 462 463 |
# File 'lib/suspenders/app_builder.rb', line 459 def run_autofixes run 'rm -rf test/' bundle_command 'exec rubocop -a' run 'i18n-tasks normalize' end |
#run_bin_setup ⇒ Object
606 607 608 609 |
# File 'lib/suspenders/app_builder.rb', line 606 def run_bin_setup run "chmod 755 bin/setup" run "bin/setup" end |
#run_webpacker_install ⇒ Object
226 227 228 |
# File 'lib/suspenders/app_builder.rb', line 226 def run_webpacker_install bundle_command "exec rails webpacker:install" end |
#set_heroku_rails_secrets ⇒ Object
522 523 524 525 526 |
# File 'lib/suspenders/app_builder.rb', line 522 def set_heroku_rails_secrets %w(staging production).each do |environment| run_heroku "config:add SECRET_KEY_BASE=#{generate_secret}", environment end end |
#set_heroku_serve_static_files ⇒ Object
528 529 530 531 532 |
# File 'lib/suspenders/app_builder.rb', line 528 def set_heroku_serve_static_files %w(staging production).each do |environment| run_heroku "config:add RAILS_SERVE_STATIC_FILES=true RAILS_LOG_TO_STDOUT=true", environment end end |
#set_ruby_to_version_being_used ⇒ Object
214 215 216 |
# File 'lib/suspenders/app_builder.rb', line 214 def set_ruby_to_version_being_used create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n" end |
#set_test_delivery_method ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/suspenders/app_builder.rb', line 18 def set_test_delivery_method inject_into_file( "config/environments/development.rb", "\n config.action_mailer.delivery_method = :test", after: "config.action_mailer.raise_delivery_errors = true", ) end |
#setup_and_push_to_origin_remote(remote_url) ⇒ Object
470 471 472 473 |
# File 'lib/suspenders/app_builder.rb', line 470 def setup_and_push_to_origin_remote(remote_url) run "git remote add origin #{remote_url}" run 'git push --all origin' end |
#setup_asset_host ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/suspenders/app_builder.rb', line 119 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("HOST"))' replace_in_file 'config/initializers/assets.rb', "config.assets.version = '1.0'", 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")' inject_into_file( "config/environments/production.rb", ' config.public_file_server.headers = { \'Cache-Control\' => "public, max-age=#{1.year.to_i}" }', after: serve_static_files_line ) end |
#setup_bundler_audit ⇒ Object
544 545 546 |
# File 'lib/suspenders/app_builder.rb', line 544 def setup_bundler_audit copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake" end |
#setup_default_rake_task ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/suspenders/app_builder.rb', line 576 def setup_default_rake_task append_file 'Rakefile' do <<-EOS task(:default).clear if defined?(RSpec) && defined?(RuboCop) require 'rubocop/rake_task' require 'rspec/core/rake_task' RuboCop::RakeTask.new task default: [:spec, :rubocop, 'bundler:audit'] end EOS end end |
#setup_deployment_environment_branches ⇒ Object
454 455 456 457 |
# File 'lib/suspenders/app_builder.rb', line 454 def setup_deployment_environment_branches run 'git branch staging' run 'git branch production' end |
#setup_foreman ⇒ Object
312 313 314 |
# File 'lib/suspenders/app_builder.rb', line 312 def setup_foreman copy_file 'Procfile', 'Procfile' end |
#setup_heroku_specific_gems ⇒ Object
230 231 232 233 234 235 236 |
# File 'lib/suspenders/app_builder.rb', line 230 def setup_heroku_specific_gems inject_into_file( "Gemfile", %{\n\s\sgem "rails_12factor"}, after: /group :staging, :production do/ ) end |
#setup_javascripts ⇒ Object
322 323 324 325 326 |
# File 'lib/suspenders/app_builder.rb', line 322 def setup_javascripts remove_file "app/assets/javascripts/application.js" copy_file "application.js", "app/assets/javascripts/application.js" create_empty_directory('app/assets/javascripts/application') end |
#setup_secret_token ⇒ Object
149 150 151 |
# File 'lib/suspenders/app_builder.rb', line 149 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#setup_segment ⇒ Object
539 540 541 542 |
# File 'lib/suspenders/app_builder.rb', line 539 def setup_segment copy_file '_analytics.html.erb', 'app/views/application/_analytics.html.erb' end |
#setup_spring ⇒ Object
548 549 550 |
# File 'lib/suspenders/app_builder.rb', line 548 def setup_spring bundle_command "exec spring binstub --all" end |
#setup_staging_environment ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/suspenders/app_builder.rb', line 135 def setup_staging_environment staging_file = 'config/environments/staging.rb' copy_file 'staging.rb', staging_file config = <<-RUBY Rails.application.configure do # ... end RUBY append_file staging_file, config end |
#setup_stylesheets ⇒ Object
316 317 318 319 320 |
# File 'lib/suspenders/app_builder.rb', line 316 def setup_stylesheets remove_file "app/assets/stylesheets/application.css" copy_file "application.scss", "app/assets/stylesheets/application.scss" end |
#use_postgres_config_template ⇒ Object
176 177 178 179 |
# File 'lib/suspenders/app_builder.rb', line 176 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |
#version_gems_in_gemfile ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/suspenders/app_builder.rb', line 190 def version_gems_in_gemfile gemfile = File.read('Gemfile') require 'bundler' locks = Bundler.locked_gems specs = locks.specs # Naively convert to single quotes gemfile.gsub! '"', "'" specs.each do |gem| name, version = gem.name, gem.version # Don't try to set version if: # * source is git or github # * version is already set gemfile.gsub! /^(?!.*, (git:|github:|'))( *gem '#{name}')/, "\\2, '~> #{version}'" end File.open 'Gemfile', 'w+' do |file| file.puts gemfile end end |