Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_active_job ⇒ Object
- #configure_available_locales ⇒ Object
- #configure_background_jobs_for_rspec ⇒ Object
- #configure_generators ⇒ Object
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_i18n_for_test_environment ⇒ Object
- #configure_i18n_tasks ⇒ Object
- #configure_letter_opener ⇒ Object
- #configure_locales ⇒ Object
- #configure_newrelic ⇒ Object
- #configure_rack_timeout ⇒ Object
- #configure_rspec ⇒ Object
- #configure_simple_form ⇒ Object
- #configure_simplecov ⇒ Object
- #configure_slim ⇒ Object
- #configure_smtp ⇒ Object
- #configure_spec_support_features ⇒ Object
- #configure_travis ⇒ Object
- #configure_unicorn ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_database ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_partials_directory ⇒ Object
- #create_production_heroku_app(flags) ⇒ Object
- #create_ruby_gemset_file ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #create_staging_heroku_app(flags) ⇒ Object
- #customize_error_pages ⇒ Object
- #disable_xml_params ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_rack_deflater ⇒ Object
- #fix_i18n_deprecation_warning ⇒ Object
- #generate_rspec ⇒ Object
- #gitignore_files ⇒ Object
- #init_git ⇒ Object
- #install_bitters ⇒ Object
- #join_heroku_app(environment) ⇒ Object
- #provide_deploy_script ⇒ Object
- #provide_dev_prime_task ⇒ Object
- #provide_setup_script ⇒ Object
- #raise_on_delivery_errors ⇒ Object
- #raise_on_unpermitted_parameters ⇒ Object
- #readme ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #replace_gemfile ⇒ Object
- #set_heroku_memory_management_variable ⇒ Object
- #set_heroku_rails_secrets ⇒ Object
- #set_heroku_remotes ⇒ Object
- #set_heroku_serve_static_files ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #set_up_factory_girl_for_rspec ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_bundler_audit ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_foreman ⇒ Object
- #setup_heroku_specific_gems ⇒ Object
- #setup_secret_token ⇒ Object
- #setup_staging_environment ⇒ Object
- #setup_stylesheets ⇒ Object
- #use_postgres_config_template ⇒ Object
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#configure_action_mailer ⇒ Object
262 263 264 265 266 267 |
# File 'lib/suspenders/app_builder.rb', line 262 def configure_action_mailer action_mailer_host "development", %{"localhost:#{port}"} 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
220 221 222 |
# File 'lib/suspenders/app_builder.rb', line 220 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_active_job ⇒ Object
277 278 279 280 281 282 |
# File 'lib/suspenders/app_builder.rb', line 277 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_available_locales ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/suspenders/app_builder.rb', line 269 def configure_available_locales config = "config.i18n.available_locales = [:en, :it]\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n" |
#configure_background_jobs_for_rspec ⇒ Object
216 217 218 |
# File 'lib/suspenders/app_builder.rb', line 216 def configure_background_jobs_for_rspec run 'rails g delayed_job:active_record' 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 = "\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
206 207 208 209 |
# File 'lib/suspenders/app_builder.rb', line 206 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
202 203 204 |
# File 'lib/suspenders/app_builder.rb', line 202 def configure_i18n_for_test_environment copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_i18n_tasks ⇒ Object
211 212 213 214 |
# File 'lib/suspenders/app_builder.rb', line 211 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_letter_opener ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/suspenders/app_builder.rb', line 14 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
237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/suspenders/app_builder.rb', line 237 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.time_zone = 'Central Time (US & Canada)'", "config.time_zone = 'Rome'" replace_in_file "config/application.rb", "# config.i18n.default_locale = :de", "config.i18n.default_locale = :it" end |
#configure_newrelic ⇒ Object
61 62 63 |
# File 'lib/suspenders/app_builder.rb', line 61 def configure_newrelic template 'newrelic.yml.erb', 'config/newrelic.yml' end |
#configure_rack_timeout ⇒ Object
250 251 252 |
# File 'lib/suspenders/app_builder.rb', line 250 def configure_rack_timeout copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb' end |
#configure_rspec ⇒ Object
191 192 193 194 195 196 |
# File 'lib/suspenders/app_builder.rb', line 191 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
258 259 260 |
# File 'lib/suspenders/app_builder.rb', line 258 def configure_simple_form bundle_command "exec rails generate simple_form:install" end |
#configure_simplecov ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/suspenders/app_builder.rb', line 224 def configure_simplecov simplecov_configuration = "require \"simplecov\"\nSimpleCov.start \"rails\" do\n add_group \"Queries\", \"app/queries\"\n add_group \"Services\", \"app/services\"\n add_group \"Validators\", \"app/validators\"\n add_group \"Presenter\", \"app/presenters\"\nend\n" prepend_to_file "spec/spec_helper.rb", simplecov_configuration end |
#configure_slim ⇒ Object
254 255 256 |
# File 'lib/suspenders/app_builder.rb', line 254 def configure_slim copy_file 'slim.rb', 'config/initializers/slim.rb' end |
#configure_smtp ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/suspenders/app_builder.rb', line 65 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
186 187 188 189 |
# File 'lib/suspenders/app_builder.rb', line 186 def configure_spec_support_features empty_directory_with_keep_file 'spec/features' empty_directory_with_keep_file 'spec/support/features' end |
#configure_travis ⇒ Object
198 199 200 |
# File 'lib/suspenders/app_builder.rb', line 198 def configure_travis template 'travis.yml.erb', '.travis.yml' end |
#configure_unicorn ⇒ Object
296 297 298 |
# File 'lib/suspenders/app_builder.rb', line 296 def configure_unicorn copy_file 'unicorn.rb', 'config/unicorn.rb' end |
#copy_miscellaneous_files ⇒ Object
432 433 434 435 |
# File 'lib/suspenders/app_builder.rb', line 432 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
145 146 147 148 149 150 |
# File 'lib/suspenders/app_builder.rb', line 145 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_database ⇒ Object
157 158 159 |
# File 'lib/suspenders/app_builder.rb', line 157 def create_database bundle_command 'exec rake db:create db:migrate' end |
#create_github_repo(repo_name) ⇒ Object
422 423 424 425 |
# File 'lib/suspenders/app_builder.rb', line 422 def create_github_repo(repo_name) path_addition = override_path_for_tests run "#{path_addition} hub create #{repo_name}" end |
#create_heroku_apps(flags) ⇒ Object
358 359 360 361 |
# File 'lib/suspenders/app_builder.rb', line 358 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_partials_directory ⇒ Object
133 134 135 |
# File 'lib/suspenders/app_builder.rb', line 133 def create_partials_directory empty_directory 'app/views/application' end |
#create_production_heroku_app(flags) ⇒ Object
352 353 354 355 356 |
# File 'lib/suspenders/app_builder.rb', line 352 def create_production_heroku_app(flags) app_name = heroku_app_name_for("production") run_heroku "create #{app_name} #{flags}", "production" end |
#create_ruby_gemset_file ⇒ Object
170 171 172 |
# File 'lib/suspenders/app_builder.rb', line 170 def create_ruby_gemset_file create_file '.ruby-gemset', "#{app_name}\n" end |
#create_shared_flashes ⇒ Object
137 138 139 |
# File 'lib/suspenders/app_builder.rb', line 137 def create_shared_flashes copy_file '_flashes.html.slim', 'app/views/application/_flashes.html.slim' end |
#create_shared_javascripts ⇒ Object
141 142 143 |
# File 'lib/suspenders/app_builder.rb', line 141 def create_shared_javascripts copy_file '_javascript.html.slim', 'app/views/application/_javascript.html.slim' end |
#create_staging_heroku_app(flags) ⇒ Object
344 345 346 347 348 349 350 |
# File 'lib/suspenders/app_builder.rb', line 344 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" end |
#customize_error_pages ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/suspenders/app_builder.rb', line 437 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" |
#disable_xml_params ⇒ Object
456 457 458 |
# File 'lib/suspenders/app_builder.rb', line 456 def disable_xml_params copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb' end |
#disallow_wrapping_parameters ⇒ Object
129 130 131 |
# File 'lib/suspenders/app_builder.rb', line 129 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#enable_database_cleaner ⇒ Object
182 183 184 |
# File 'lib/suspenders/app_builder.rb', line 182 def enable_database_cleaner copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_rack_deflater ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/suspenders/app_builder.rb', line 81 def enable_rack_deflater config = "\n # Enable deflate / gzip compression of controller-generated responses\n config.middleware.use Rack::Deflater\n RUBY\n\n inject_into_file(\n \"config/environments/production.rb\",\n config,\n after: serve_static_files_line\n )\nend\n" |
#fix_i18n_deprecation_warning ⇒ Object
284 285 286 287 288 289 290 |
# File 'lib/suspenders/app_builder.rb', line 284 def fix_i18n_deprecation_warning config = "config.i18n.enforce_available_locales = true\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n" |
#generate_rspec ⇒ Object
292 293 294 |
# File 'lib/suspenders/app_builder.rb', line 292 def generate_rspec generate 'rspec:install' end |
#gitignore_files ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/suspenders/app_builder.rb', line 315 def gitignore_files remove_file '.gitignore' copy_file 'suspenders_gitignore', '.gitignore' [ 'app/forms', 'app/presenters', 'app/queries', 'app/services', 'app/views/pages', 'spec/controllers', 'spec/forms', 'spec/helpers', 'spec/lib', 'spec/presenters', 'spec/queries', 'spec/services', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| run "mkdir #{dir}" run "touch #{dir}/.keep" end end |
#init_git ⇒ Object
340 341 342 |
# File 'lib/suspenders/app_builder.rb', line 340 def init_git run 'git init' end |
#install_bitters ⇒ Object
311 312 313 |
# File 'lib/suspenders/app_builder.rb', line 311 def install_bitters run "bitters install --path app/assets/stylesheets" end |
#join_heroku_app(environment) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/suspenders/app_builder.rb', line 374 def join_heroku_app(environment) heroku_app_name = heroku_app_name_for(environment) "if heroku join --app \#{heroku_app_name} &> /dev/null; then\n git remote add \#{environment} [email protected]:\#{heroku_app_name}.git || true\n printf 'You are a collaborator on the \"\#{heroku_app_name}\" Heroku app\\n'\nelse\n printf 'Ask for access to the \"\#{heroku_app_name}\" Heroku app\\n'\nfi\n SHELL\nend\n" |
#provide_deploy_script ⇒ Object
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/suspenders/app_builder.rb', line 404 def provide_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" |
#provide_dev_prime_task ⇒ Object
35 36 37 |
# File 'lib/suspenders/app_builder.rb', line 35 def provide_dev_prime_task copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake' end |
#provide_setup_script ⇒ Object
30 31 32 33 |
# File 'lib/suspenders/app_builder.rb', line 30 def provide_setup_script template "bin_setup.erb", "bin/setup", port_number: port, force: true run "chmod a+x bin/setup" end |
#raise_on_delivery_errors ⇒ Object
9 10 11 12 |
# File 'lib/suspenders/app_builder.rb', line 9 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
22 23 24 25 26 27 28 |
# File 'lib/suspenders/app_builder.rb', line 22 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
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
450 451 452 453 454 |
# File 'lib/suspenders/app_builder.rb', line 450 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
161 162 163 164 |
# File 'lib/suspenders/app_builder.rb', line 161 def replace_gemfile remove_file 'Gemfile' template 'Gemfile.erb', 'Gemfile' end |
#set_heroku_memory_management_variable ⇒ Object
392 393 394 395 396 |
# File 'lib/suspenders/app_builder.rb', line 392 def set_heroku_memory_management_variable %w(staging production).each do |environment| run_heroku "config:add NEW_RELIC_AGGRESSIVE_KEEPALIVE=1", environment end end |
#set_heroku_rails_secrets ⇒ Object
386 387 388 389 390 |
# File 'lib/suspenders/app_builder.rb', line 386 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_remotes ⇒ Object
363 364 365 366 367 368 369 370 371 372 |
# File 'lib/suspenders/app_builder.rb', line 363 def set_heroku_remotes remotes = "\n# Set up the staging and production apps.\n\#{join_heroku_app('staging')}\n\#{join_heroku_app('production')}\n SHELL\n\n append_file 'bin/setup', remotes\nend\n" |
#set_heroku_serve_static_files ⇒ Object
398 399 400 401 402 |
# File 'lib/suspenders/app_builder.rb', line 398 def set_heroku_serve_static_files %w(staging production).each do |environment| run_heroku "config:add RAILS_SERVE_STATIC_FILES=true", environment end end |
#set_ruby_to_version_being_used ⇒ Object
166 167 168 |
# File 'lib/suspenders/app_builder.rb', line 166 def set_ruby_to_version_being_used create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n" end |
#set_up_factory_girl_for_rspec ⇒ Object
57 58 59 |
# File 'lib/suspenders/app_builder.rb', line 57 def set_up_factory_girl_for_rspec copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb' end |
#setup_asset_host ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/suspenders/app_builder.rb', line 95 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.static_cache_control = "public, max-age=#{1.year.to_i}"', after: serve_static_files_line ) end |
#setup_bundler_audit ⇒ Object
427 428 429 430 |
# File 'lib/suspenders/app_builder.rb', line 427 def setup_bundler_audit copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake" append_file "Rakefile", %{\ntask default: "bundler:audit"\n} end |
#setup_default_rake_task ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/suspenders/app_builder.rb', line 460 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_foreman ⇒ Object
300 301 302 303 |
# File 'lib/suspenders/app_builder.rb', line 300 def setup_foreman copy_file 'sample.env', '.sample.env' copy_file 'Procfile', 'Procfile' end |
#setup_heroku_specific_gems ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/suspenders/app_builder.rb', line 174 def setup_heroku_specific_gems inject_into_file( "Gemfile", %{\n\s\sgem "rails_stdout_logging"}, after: /group :staging, :production do/ ) end |
#setup_secret_token ⇒ Object
125 126 127 |
# File 'lib/suspenders/app_builder.rb', line 125 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#setup_staging_environment ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/suspenders/app_builder.rb', line 111 def setup_staging_environment staging_file = 'config/environments/staging.rb' copy_file 'staging.rb', staging_file config = "\nRails.application.configure do\n # ...\nend\n RUBY\n\n append_file staging_file, config\nend\n" |
#setup_stylesheets ⇒ Object
305 306 307 308 309 |
# File 'lib/suspenders/app_builder.rb', line 305 def setup_stylesheets remove_file 'app/assets/stylesheets/application.css' copy_file 'application.css.sass', 'app/assets/stylesheets/application.css.sass' end |
#use_postgres_config_template ⇒ Object
152 153 154 155 |
# File 'lib/suspenders/app_builder.rb', line 152 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |