Class: Suspenders::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Extended by:
Forwardable
Includes:
Actions
Defined in:
lib/suspenders/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file

Instance Method Details

#add_bullet_gem_configurationObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/suspenders/app_builder.rb', line 59

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"

#configure_action_mailerObject



335
336
337
338
339
# File 'lib/suspenders/app_builder.rb', line 335

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_specsObject



290
291
292
# File 'lib/suspenders/app_builder.rb', line 290

def configure_action_mailer_in_specs
  copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
end

#configure_active_adminObject



315
316
317
318
319
# File 'lib/suspenders/app_builder.rb', line 315

def configure_active_admin
  bundle_command "exec rails generate active_admin:install --skip-users"
  bundle_command "exec rake db:migrate"
  bundle_command "exec rake db:seed"
end

#configure_active_jobObject



341
342
343
344
345
346
# File 'lib/suspenders/app_builder.rb', line 341

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_deploymentObject



440
441
442
443
444
445
446
447
448
449
450
# File 'lib/suspenders/app_builder.rb', line 440

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_rspecObject



286
287
288
# File 'lib/suspenders/app_builder.rb', line 286

def configure_background_jobs_for_rspec
  bundle_command 'exec rails generate delayed_job:active_record'
end

#configure_capybara_webkitObject



294
295
296
# File 'lib/suspenders/app_builder.rb', line 294

def configure_capybara_webkit
  copy_file "capybara_webkit.rb", "spec/support/capybara_webkit.rb"
end

#configure_ciObject



273
274
275
# File 'lib/suspenders/app_builder.rb', line 273

def configure_ci
  template "circle.yml.erb", "circle.yml"
end

#configure_deviseObject



310
311
312
313
# File 'lib/suspenders/app_builder.rb', line 310

def configure_devise
  bundle_command "exec rails generate devise:install"
  bundle_command "exec rake db:migrate"
end

#configure_generatorsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/suspenders/app_builder.rb', line 101

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_translationsObject



281
282
283
284
# File 'lib/suspenders/app_builder.rb', line 281

def configure_i18n_for_missing_translations
  raise_on_missing_translations_in("development")
  raise_on_missing_translations_in("test")
end

#configure_i18n_for_test_environmentObject



277
278
279
# File 'lib/suspenders/app_builder.rb', line 277

def configure_i18n_for_test_environment
  copy_file "i18n.rb", "spec/support/i18n.rb"
end

#configure_initjsObject



321
322
323
# File 'lib/suspenders/app_builder.rb', line 321

def configure_initjs
  bundle_command 'exec rails generate initjs:install'
end

#configure_quiet_assetsObject



84
85
86
87
88
89
90
# File 'lib/suspenders/app_builder.rb', line 84

def configure_quiet_assets
  config = "config.quiet_assets = true\n  RUBY\n\n  inject_into_class \"config/application.rb\", \"Application\", config\nend\n"

#configure_rspecObject



266
267
268
269
270
271
# File 'lib/suspenders/app_builder.rb', line 266

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_formObject



303
304
305
306
307
308
# File 'lib/suspenders/app_builder.rb', line 303

def configure_simple_form
  bundle_command "exec rails generate simple_form:install --bootstrap"
  inject_into_file "app/assets/javascripts/application.js",
                   "\n//= require bootstrap",
                   after: "//= require_tree ."
end

#configure_smtpObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/suspenders/app_builder.rb', line 131

def configure_smtp
  config = "\nActionMailer::Base.smtp_settings = {\n  address: 'smtp.sendgrid.net',\n  port: '587',\n  authentication: :plain,\n  user_name: ENV['SENDGRID_USERNAME'],\n  password: ENV['SENDGRID_PASSWORD'],\n  domain: 'heroku.com',\n  enable_starttls_auto: true\n}\n\n  RUBY\n\n  inject_into_file 'config/environment.rb', config,\n    before: \"Rails.application.initialize!\"\nend\n"

#configure_spec_support_featuresObject



261
262
263
264
# File 'lib/suspenders/app_builder.rb', line 261

def configure_spec_support_features
  empty_directory_with_keep_file 'spec/features'
  empty_directory_with_keep_file 'spec/support/features'
end

#configure_time_formatsObject



298
299
300
301
# File 'lib/suspenders/app_builder.rb', line 298

def configure_time_formats
  remove_file "config/locales/en.yml"
  template "config_locales_en.yml.erb", "config/locales/en.yml"
end

#copy_dotfilesObject



409
410
411
# File 'lib/suspenders/app_builder.rb', line 409

def copy_dotfiles
  directory("dotfiles", ".")
end

#copy_flash_javascript_fileObject



325
326
327
# File 'lib/suspenders/app_builder.rb', line 325

def copy_flash_javascript_file
  template "flash.js.coffee.erb", "app/assets/javascripts/#{self.app_name.underscore}/modules/flash.js.coffee"
end

#copy_miscellaneous_filesObject



470
471
472
473
474
# File 'lib/suspenders/app_builder.rb', line 470

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


232
233
234
# File 'lib/suspenders/app_builder.rb', line 232

def create_application_footer
  copy_file '_footer.html.slim', 'app/views/partials/_footer.html.slim'
end

#create_application_headerObject



228
229
230
# File 'lib/suspenders/app_builder.rb', line 228

def create_application_header
  copy_file '_header.html.slim', 'app/views/partials/_header.html.slim'
end

#create_application_layoutObject



222
223
224
225
226
# File 'lib/suspenders/app_builder.rb', line 222

def create_application_layout
  template 'suspenders_layout.html.slim',
           'app/views/layouts/application.html.slim',
           force: true
end

#create_databaseObject



242
243
244
# File 'lib/suspenders/app_builder.rb', line 242

def create_database
  bundle_command 'exec rake db:create db:migrate'
end

#create_github_repo(repo_name) ⇒ Object



452
453
454
# File 'lib/suspenders/app_builder.rb', line 452

def create_github_repo(repo_name)
  run "hub create #{repo_name}"
end

#create_heroku_apps(flags) ⇒ Object



417
418
419
420
# File 'lib/suspenders/app_builder.rb', line 417

def create_heroku_apps(flags)
  create_staging_heroku_app(flags)
  create_production_heroku_app(flags)
end

#create_partials_directoryObject



210
211
212
# File 'lib/suspenders/app_builder.rb', line 210

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



214
215
216
# File 'lib/suspenders/app_builder.rb', line 214

def create_shared_flashes
  copy_file "_flash.html.slim", "app/views/layouts/_flash.html.slim"
end

#create_shared_javascriptsObject



218
219
220
# File 'lib/suspenders/app_builder.rb', line 218

def create_shared_javascripts
  copy_file '_javascripts.html.slim', 'app/views/partials/_javascripts.html.slim'
end

#customize_error_pagesObject



476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/suspenders/app_builder.rb', line 476

def customize_error_pages
  meta_tags ="  <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_paramsObject



517
518
519
# File 'lib/suspenders/app_builder.rb', line 517

def disable_xml_params
  copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
end

#disallow_wrapping_parametersObject



206
207
208
# File 'lib/suspenders/app_builder.rb', line 206

def disallow_wrapping_parameters
  remove_file "config/initializers/wrap_parameters.rb"
end

#enable_database_cleanerObject



250
251
252
# File 'lib/suspenders/app_builder.rb', line 250

def enable_database_cleaner
  copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end

#enable_rack_deflaterObject



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/suspenders/app_builder.rb', line 150

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"

#gemfileObject



27
28
29
# File 'lib/suspenders/app_builder.rb', line 27

def gemfile
  template "Gemfile.erb", "Gemfile"
end

#generate_factories_fileObject



123
124
125
# File 'lib/suspenders/app_builder.rb', line 123

def generate_factories_file
  copy_file "factories.rb", "spec/factories.rb"
end

#generate_rspecObject



348
349
350
# File 'lib/suspenders/app_builder.rb', line 348

def generate_rspec
  generate 'rspec:install'
end

#gitignoreObject



23
24
25
# File 'lib/suspenders/app_builder.rb', line 23

def gitignore
  copy_file "suspenders_gitignore", ".gitignore"
end

#init_gitObject



413
414
415
# File 'lib/suspenders/app_builder.rb', line 413

def init_git
  run 'git init'
end

#provide_deploy_scriptObject



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/suspenders/app_builder.rb', line 422

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_taskObject



97
98
99
# File 'lib/suspenders/app_builder.rb', line 97

def provide_dev_prime_task
  copy_file 'dev.rake', 'lib/tasks/dev.rake'
end

#provide_setup_scriptObject



92
93
94
95
# File 'lib/suspenders/app_builder.rb', line 92

def provide_setup_script
  template "bin_setup", "bin/setup", force: true
  run "chmod a+x bin/setup"
end

#provide_shoulda_matchers_configObject



254
255
256
257
258
259
# File 'lib/suspenders/app_builder.rb', line 254

def provide_shoulda_matchers_config
  copy_file(
    "shoulda_matchers_config_rspec.rb",
    "spec/support/shoulda_matchers.rb"
  )
end

#raise_on_delivery_errorsObject



46
47
48
49
# File 'lib/suspenders/app_builder.rb', line 46

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_testObject



38
39
40
41
42
43
44
# File 'lib/suspenders/app_builder.rb', line 38

def raise_on_missing_assets_in_test
  inject_into_file(
    "config/environments/test.rb",
    "\n  config.assets.raise_runtime_errors = true",
    after: "Rails.application.configure do",
  )
end

#raise_on_unpermitted_parametersObject



76
77
78
79
80
81
82
# File 'lib/suspenders/app_builder.rb', line 76

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"

#readmeObject



19
20
21
# File 'lib/suspenders/app_builder.rb', line 19

def readme
  template 'README.md.erb', 'README.md'
end

#remove_config_comment_linesObject



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/suspenders/app_builder.rb', line 489

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_linesObject



511
512
513
514
515
# File 'lib/suspenders/app_builder.rb', line 511

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_flash_javascript_fileObject



329
330
331
332
333
# File 'lib/suspenders/app_builder.rb', line 329

def replace_flash_javascript_file
  replace_in_file "app/assets/javascripts/#{self.app_name.underscore}/#{self.app_name.underscore}.js.coffee",
                  "modules: -> []",
                  "modules: -> [#{self.app_name.camelize}.Flash]"
end

#set_ruby_to_version_being_usedObject



246
247
248
# File 'lib/suspenders/app_builder.rb', line 246

def set_ruby_to_version_being_used
  create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n"
end

#set_test_delivery_methodObject



51
52
53
54
55
56
57
# File 'lib/suspenders/app_builder.rb', line 51

def set_test_delivery_method
  inject_into_file(
    "config/environments/development.rb",
    "\n  config.action_mailer.delivery_method = :letter_opener",
    after: "config.action_mailer.raise_delivery_errors = true",
  )
end

#set_up_factory_girl_for_rspecObject



119
120
121
# File 'lib/suspenders/app_builder.rb', line 119

def set_up_factory_girl_for_rspec
  copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
end

#set_up_foregoObject



352
353
354
# File 'lib/suspenders/app_builder.rb', line 352

def set_up_forego
  copy_file "Procfile", "Procfile"
end

#set_up_houndObject



127
128
129
# File 'lib/suspenders/app_builder.rb', line 127

def set_up_hound
  copy_file "hound.yml", ".hound.yml"
end

#setup_asset_hostObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/suspenders/app_builder.rb', line 164

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 = 'https://#{self.app_name}.herokuapp.com'"

  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_basic_stylesheet_foldersObject



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/suspenders/app_builder.rb', line 363

def setup_basic_stylesheet_folders
  imports = "\n// ==== Variables\n@import 'variables/colors';\n@import 'variables/variables';\n// ==== Base\n@import 'base/base';\n@import 'base/font';\n@import 'base/utility';\n// ==== Components\n@import 'components/navbar';\n@import 'components/title';\n@import 'components/buttons';\n@import 'components/forms';\n  STYLESHEETS\n\n  inject_into_file \"app/assets/stylesheets/application.scss\",\n                   imports,\n                   after: '@import \"font-awesome\";'\n\n  directory(\"stylesheets\", \"app/assets/stylesheets\", recursive: true)\nend\n"

#setup_bundler_auditObject



461
462
463
464
# File 'lib/suspenders/app_builder.rb', line 461

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_directoriesObject



395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/suspenders/app_builder.rb', line 395

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_taskObject



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/suspenders/app_builder.rb', line 521

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_flash_stylesheetObject



387
388
389
390
391
392
393
# File 'lib/suspenders/app_builder.rb', line 387

def setup_flash_stylesheet
  copy_file "_flash.scss", "app/assets/stylesheets/componentes/_flash.scss"

  inject_into_file "app/assets/stylesheets/application.scss",
                   "\n@import 'components/flash';",
                   after: "@import 'components/forms';"
end

#setup_rack_mini_profilerObject



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_tokenObject



202
203
204
# File 'lib/suspenders/app_builder.rb', line 202

def setup_secret_token
  template 'secrets.yml', 'config/secrets.yml', force: true
end

#setup_segmentObject



456
457
458
459
# File 'lib/suspenders/app_builder.rb', line 456

def setup_segment
  copy_file '_analytics.html.erb',
    'app/views/application/_analytics.html.erb'
end

#setup_springObject



466
467
468
# File 'lib/suspenders/app_builder.rb', line 466

def setup_spring
  bundle_command "exec spring binstub --all"
end

#setup_staging_environmentObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/suspenders/app_builder.rb', line 180

def setup_staging_environment
  staging_file = 'config/environments/staging.rb'
  copy_file 'staging.rb', staging_file

  config = "\nRails.application.configure do\n  if ENV.fetch(\"HEROKU_APP_NAME\", \"\").include?(\"staging-pr-\")\nconfig.action_mailer.asset_host = (\"https://\" + ENV[\"HEROKU_APP_NAME\"] + \".herokuapp.com\")\nconfig.action_mailer.default_url_options = { host: ENV[\"HEROKU_APP_NAME\"] + \".herokuapp.com\" }\nconfig.action_controller.default_url_options = { host: ENV[\"HEROKU_APP_NAME\"] + \".herokuapp.com\" }\n  else\nconfig.action_mailer.asset_host = (\"https://\" + ENV[\"HEROKU_APP_NAME\"]+ \"-staging\" + \".herokuapp.com\")\nconfig.action_mailer.default_url_options = { host: ENV[\"HEROKU_APP_NAME\"]+ \"-staging\" + \".herokuapp.com\" }\nconfig.action_controller.default_url_options = { host: ENV[\"HEROKU_APP_NAME\"]+ \"-staging\" + \".herokuapp.com\" }\n  end\nend\n  RUBY\n\n  append_file staging_file, config\nend\n"

#setup_stylesheetsObject



356
357
358
359
360
361
# File 'lib/suspenders/app_builder.rb', line 356

def setup_stylesheets
  remove_file "app/assets/stylesheets/application.css"

  copy_file "application.scss",
            "app/assets/stylesheets/application.scss"
end

#uncomment_devise_secret_tokenObject



537
538
539
540
# File 'lib/suspenders/app_builder.rb', line 537

def uncomment_devise_secret_token
  config = "config.secret_key"
  uncomment_lines("config/initializers/devise.rb", config)
end

#use_postgres_config_templateObject



236
237
238
239
240
# File 'lib/suspenders/app_builder.rb', line 236

def use_postgres_config_template
  template 'postgresql_database.yml.erb',
           'config/database.yml',
           force: true
end