Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #add_bullet_gem_configuration ⇒ Object
- #add_helpers_for_rspec ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_active_job ⇒ Object
- #configure_background_jobs_for_rspec ⇒ Object
- #configure_capybara_webkit ⇒ Object
- #configure_generators ⇒ Object
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_i18n_for_test_environment ⇒ Object
- #configure_letter_opener ⇒ Object
- #configure_locales ⇒ Object
- #configure_puma ⇒ Object
- #configure_quiet_assets ⇒ Object
- #configure_rack_timeout ⇒ Object
- #configure_rspec ⇒ Object
- #configure_simple_form ⇒ Object
- #configure_slim ⇒ Object
- #configure_smtp ⇒ Object
- #configure_spec_support_features ⇒ Object
- #copy_dotfiles ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_binstubs ⇒ Object
- #create_database ⇒ Object
- #create_deploy_script ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_partials_directory ⇒ Object
- #create_ruby_gemset_file ⇒ Object
- #create_shared_css_overrides ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #customize_error_pages ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_rack_canonical_host ⇒ Object
- #enable_rack_deflater ⇒ Object
- #gemfile ⇒ Object
- #generate_rspec ⇒ Object
- #gitignore ⇒ Object
- #init_git ⇒ 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
- #readme ⇒ Object
- #remove_config_comment_lines ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #replace_gemfile(path) ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #set_up_factory_girl_for_rspec ⇒ Object
- #set_up_faker ⇒ Object
- #set_up_forego ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_brakeman ⇒ Object
- #setup_bundler_audit ⇒ Object
- #setup_default_directories ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_rack_mini_profiler ⇒ Object
- #setup_rubocop ⇒ Object
- #setup_secret_token ⇒ Object
- #setup_spring ⇒ Object
- #use_postgres_config_template ⇒ Object
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#add_bullet_gem_configuration ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/suspenders/app_builder.rb', line 55 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_helpers_for_rspec ⇒ Object
119 120 121 122 |
# File 'lib/suspenders/app_builder.rb', line 119 def add_helpers_for_rspec copy_file 'queries_helper_rspec.rb', 'spec/support/queries_helper.rb' copy_file 'fixtures_helper_rspec.rb', 'spec/support/fixtures_helper.rb' end |
#configure_action_mailer ⇒ Object
321 322 323 324 325 |
# File 'lib/suspenders/app_builder.rb', line 321 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
278 279 280 |
# File 'lib/suspenders/app_builder.rb', line 278 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_active_job ⇒ Object
327 328 329 330 331 332 |
# File 'lib/suspenders/app_builder.rb', line 327 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_background_jobs_for_rspec ⇒ Object
274 275 276 |
# File 'lib/suspenders/app_builder.rb', line 274 def configure_background_jobs_for_rspec run 'rails g delayed_job:active_record' end |
#configure_capybara_webkit ⇒ Object
282 283 284 |
# File 'lib/suspenders/app_builder.rb', line 282 def copy_file "capybara_webkit.rb", "spec/support/capybara_webkit.rb" end |
#configure_generators ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/suspenders/app_builder.rb', line 97 def configure_generators config = "\nconfig.generators do |generate|\n generate.helper false\n generate.javascript_engine false\n generate.request_specs false\n generate.routing_specs false\n generate.stylesheets false\n generate.test_framework :rspec\n generate.view_specs false\nend\n\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n" |
#configure_i18n_for_missing_translations ⇒ Object
269 270 271 272 |
# File 'lib/suspenders/app_builder.rb', line 269 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
265 266 267 |
# File 'lib/suspenders/app_builder.rb', line 265 def configure_i18n_for_test_environment copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_letter_opener ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/suspenders/app_builder.rb', line 47 def configure_letter_opener inject_into_file( "config/environments/development.rb", "\n config.action_mailer.delivery_method = :letter_opener", after: "config.action_mailer.raise_delivery_errors = true", ) end |
#configure_locales ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/suspenders/app_builder.rb', line 286 def configure_locales remove_file "config/locales/en.yml" template "config_locales_it.yml.erb", "config/locales/it.yml" replace_in_file "config/application.rb", "# config.i18n.default_locale = :de", "config.i18n.default_locale = :it" replace_in_file "config/application.rb", "# config.time_zone = 'Central Time (US & Canada)'", "config.time_zone = 'Rome'" available_locales_config = "config.i18n.available_locales = [:en, :it]\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', available_locales_config\nend\n" |
#configure_puma ⇒ Object
338 339 340 |
# File 'lib/suspenders/app_builder.rb', line 338 def configure_puma copy_file "puma.rb", "config/puma.rb" end |
#configure_quiet_assets ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/suspenders/app_builder.rb', line 80 def configure_quiet_assets config = "config.quiet_assets = true\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n" |
#configure_rack_timeout ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/suspenders/app_builder.rb', line 305 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
258 259 260 261 262 263 |
# File 'lib/suspenders/app_builder.rb', line 258 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_simple_form ⇒ Object
317 318 319 |
# File 'lib/suspenders/app_builder.rb', line 317 def configure_simple_form bundle_command "exec rails generate simple_form:install" end |
#configure_slim ⇒ Object
313 314 315 |
# File 'lib/suspenders/app_builder.rb', line 313 def configure_slim copy_file 'slim.rb', 'config/initializers/slim.rb' end |
#configure_smtp ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/suspenders/app_builder.rb', line 128 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
253 254 255 256 |
# File 'lib/suspenders/app_builder.rb', line 253 def configure_spec_support_features empty_directory_with_keep_file 'spec/features' empty_directory_with_keep_file 'spec/support/features' end |
#copy_dotfiles ⇒ Object
369 370 371 |
# File 'lib/suspenders/app_builder.rb', line 369 def copy_dotfiles directory("dotfiles", ".") end |
#copy_miscellaneous_files ⇒ Object
426 427 428 429 430 |
# File 'lib/suspenders/app_builder.rb', line 426 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
208 209 210 211 212 213 |
# File 'lib/suspenders/app_builder.rb', line 208 def create_application_layout remove_file 'app/views/layouts/application.html.erb' template 'suspenders_layout.html.slim', 'app/views/layouts/application.html.slim', force: true end |
#create_binstubs ⇒ Object
421 422 423 424 |
# File 'lib/suspenders/app_builder.rb', line 421 def create_binstubs bundle_command "binstubs brakeman" bundle_command "binstubs rubocop" end |
#create_database ⇒ Object
220 221 222 |
# File 'lib/suspenders/app_builder.rb', line 220 def create_database bundle_command 'exec rake db:create db:migrate' end |
#create_deploy_script ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/suspenders/app_builder.rb', line 382 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
400 401 402 |
# File 'lib/suspenders/app_builder.rb', line 400 def create_github_repo(repo_name) run "hub create #{repo_name}" end |
#create_heroku_apps(flags) ⇒ Object
377 378 379 380 |
# File 'lib/suspenders/app_builder.rb', line 377 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_partials_directory ⇒ Object
188 189 190 |
# File 'lib/suspenders/app_builder.rb', line 188 def create_partials_directory empty_directory 'app/views/application' end |
#create_ruby_gemset_file ⇒ Object
238 239 240 |
# File 'lib/suspenders/app_builder.rb', line 238 def create_ruby_gemset_file create_file '.ruby-gemset', "#{app_name}\n" end |
#create_shared_css_overrides ⇒ Object
201 202 203 204 205 206 |
# File 'lib/suspenders/app_builder.rb', line 201 def create_shared_css_overrides copy_file( "_css_overrides.html.erb", "app/views/application/_css_overrides.html.erb", ) end |
#create_shared_flashes ⇒ Object
192 193 194 195 |
# File 'lib/suspenders/app_builder.rb', line 192 def create_shared_flashes copy_file '_flashes.html.slim', 'app/views/application/_flashes.html.slim' copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb" end |
#create_shared_javascripts ⇒ Object
197 198 199 |
# File 'lib/suspenders/app_builder.rb', line 197 def create_shared_javascripts copy_file '_javascript.html.slim', 'app/views/application/_javascript.html.slim' end |
#customize_error_pages ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/suspenders/app_builder.rb', line 432 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" |
#disallow_wrapping_parameters ⇒ Object
184 185 186 |
# File 'lib/suspenders/app_builder.rb', line 184 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#enable_database_cleaner ⇒ Object
242 243 244 |
# File 'lib/suspenders/app_builder.rb', line 242 def enable_database_cleaner copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_rack_canonical_host ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/suspenders/app_builder.rb', line 144 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
161 162 163 |
# File 'lib/suspenders/app_builder.rb', line 161 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_rspec ⇒ Object
334 335 336 |
# File 'lib/suspenders/app_builder.rb', line 334 def generate_rspec generate 'rspec:install' 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
373 374 375 |
# File 'lib/suspenders/app_builder.rb', line 373 def init_git run 'git init' end |
#provide_dev_prime_task ⇒ Object
93 94 95 |
# File 'lib/suspenders/app_builder.rb', line 93 def provide_dev_prime_task copy_file 'dev.rake', 'lib/tasks/dev.rake' end |
#provide_setup_script ⇒ Object
88 89 90 91 |
# File 'lib/suspenders/app_builder.rb', line 88 def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end |
#provide_shoulda_matchers_config ⇒ Object
246 247 248 249 250 251 |
# File 'lib/suspenders/app_builder.rb', line 246 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
72 73 74 75 76 77 78 |
# File 'lib/suspenders/app_builder.rb', line 72 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" |
#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
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/suspenders/app_builder.rb', line 445 def remove_config_comment_lines config_files = [ "application.rb", "environment.rb", "environments/development.rb", "environments/production.rb", "environments/test.rb", ] config_files.each do |config_file| path = File.join(destination_root, "config/#{config_file}") accepted_content = File.readlines(path).reject do |line| line =~ /^.*#.*$/ || line =~ /^$\n/ end File.open(path, "w") do |file| accepted_content.each { |line| file.puts line } end end end |
#remove_routes_comment_lines ⇒ Object
467 468 469 470 471 |
# File 'lib/suspenders/app_builder.rb', line 467 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(path) ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'lib/suspenders/app_builder.rb', line 224 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 |
#set_ruby_to_version_being_used ⇒ Object
234 235 236 |
# File 'lib/suspenders/app_builder.rb', line 234 def set_ruby_to_version_being_used create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n" end |
#set_up_factory_girl_for_rspec ⇒ Object
115 116 117 |
# File 'lib/suspenders/app_builder.rb', line 115 def set_up_factory_girl_for_rspec copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb' end |
#set_up_faker ⇒ Object
124 125 126 |
# File 'lib/suspenders/app_builder.rb', line 124 def set_up_faker copy_file 'faker_rspec.rb', 'spec/support/faker.rb' end |
#set_up_forego ⇒ Object
342 343 344 |
# File 'lib/suspenders/app_builder.rb', line 342 def set_up_forego copy_file "Procfile", "Procfile" end |
#setup_asset_host ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/suspenders/app_builder.rb', line 165 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")' configure_environment( "production", 'config.static_cache_control = "public, max-age=31557600"', ) end |
#setup_brakeman ⇒ Object
408 409 410 |
# File 'lib/suspenders/app_builder.rb', line 408 def setup_brakeman copy_file "brakeman.rake", "lib/tasks/brakeman.rake" end |
#setup_bundler_audit ⇒ Object
404 405 406 |
# File 'lib/suspenders/app_builder.rb', line 404 def setup_bundler_audit copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake" end |
#setup_default_directories ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/suspenders/app_builder.rb', line 346 def setup_default_directories [ 'app/forms', 'app/decorators', 'app/queries', 'app/services', 'app/views/pages', 'spec/controllers', 'spec/forms', 'spec/helpers', 'spec/lib', 'spec/decorators', 'spec/queries', 'spec/services', 'spec/fixtures', '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
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/suspenders/app_builder.rb', line 473 def setup_default_rake_task append_file 'Rakefile' do "task(:default).clear\n\nif defined? RSpec\n task(:spec).clear\n RSpec::Core::RakeTask.new(:spec) do |t|\nt.verbose = false\n end\nend\n\ntask default: :rubocop\ntask default: :spec\ntask default: \"brakeman:check\"\ntask default: \"bundler:audit\"\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_rubocop ⇒ Object
412 413 414 415 |
# File 'lib/suspenders/app_builder.rb', line 412 def setup_rubocop copy_file "rubocop.rake", "lib/tasks/rubocop.rake" copy_file "rubocop.yml", ".rubocop.yml" end |
#setup_secret_token ⇒ Object
180 181 182 |
# File 'lib/suspenders/app_builder.rb', line 180 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#setup_spring ⇒ Object
417 418 419 |
# File 'lib/suspenders/app_builder.rb', line 417 def setup_spring bundle_command "exec spring binstub --all" end |
#use_postgres_config_template ⇒ Object
215 216 217 218 |
# File 'lib/suspenders/app_builder.rb', line 215 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |