Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
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_configuration ⇒ Object
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"
|
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
|
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
|
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
|
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
|
424
425
426
427
428
429
430
431
432
433
434
|
# File 'lib/suspenders/app_builder.rb', line 424
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
|
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
|
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
|
273
274
275
|
# File 'lib/suspenders/app_builder.rb', line 273
def configure_ci
template "circle.yml.erb", "circle.yml"
end
|
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
|
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"
|
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
|
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
|
321
322
323
|
# File 'lib/suspenders/app_builder.rb', line 321
def configure_initjs
bundle_command 'exec rails generate initjs:install'
end
|
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"
|
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
|
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",
"//= require bootstrap",
after: "//= require_tree ."
end
|
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"
|
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
|
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_dotfiles ⇒ Object
393
394
395
|
# File 'lib/suspenders/app_builder.rb', line 393
def copy_dotfiles
directory("dotfiles", ".")
end
|
#copy_flash_javascript_file ⇒ Object
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_files ⇒ Object
454
455
456
457
458
|
# File 'lib/suspenders/app_builder.rb', line 454
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
copy_file '_footer.html.slim', 'app/views/partials/_footer.html.slim'
end
|
228
229
230
|
# File 'lib/suspenders/app_builder.rb', line 228
def
copy_file '_header.html.slim', 'app/views/partials/_header.html.slim'
end
|
#create_application_layout ⇒ Object
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_database ⇒ Object
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
436
437
438
|
# File 'lib/suspenders/app_builder.rb', line 436
def create_github_repo(repo_name)
run "hub create #{repo_name}"
end
|
#create_heroku_apps(flags) ⇒ Object
401
402
403
404
|
# File 'lib/suspenders/app_builder.rb', line 401
def create_heroku_apps(flags)
create_staging_heroku_app(flags)
create_production_heroku_app(flags)
end
|
#create_partials_directory ⇒ Object
210
211
212
|
# File 'lib/suspenders/app_builder.rb', line 210
def create_partials_directory
empty_directory 'app/views/application'
end
|
#create_shared_flashes ⇒ Object
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_javascripts ⇒ Object
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_pages ⇒ Object
460
461
462
463
464
465
466
467
468
469
470
471
|
# File 'lib/suspenders/app_builder.rb', line 460
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_params ⇒ Object
501
502
503
|
# File 'lib/suspenders/app_builder.rb', line 501
def disable_xml_params
copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
end
|
#disallow_wrapping_parameters ⇒ Object
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_cleaner ⇒ Object
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_deflater ⇒ Object
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"
|
#gemfile ⇒ Object
27
28
29
|
# File 'lib/suspenders/app_builder.rb', line 27
def gemfile
template "Gemfile.erb", "Gemfile"
end
|
#generate_factories_file ⇒ Object
123
124
125
|
# File 'lib/suspenders/app_builder.rb', line 123
def generate_factories_file
copy_file "factories.rb", "spec/factories.rb"
end
|
#generate_rspec ⇒ Object
348
349
350
|
# File 'lib/suspenders/app_builder.rb', line 348
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
397
398
399
|
# File 'lib/suspenders/app_builder.rb', line 397
def init_git
run 'git init'
end
|
#provide_deploy_script ⇒ Object
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'lib/suspenders/app_builder.rb', line 406
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
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_script ⇒ Object
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_config ⇒ Object
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_errors ⇒ Object
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_test ⇒ Object
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_parameters ⇒ Object
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"
|
#readme ⇒ Object
19
20
21
|
# File 'lib/suspenders/app_builder.rb', line 19
def readme
template 'README.md.erb', 'README.md'
end
|
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
# File 'lib/suspenders/app_builder.rb', line 473
def
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
|
495
496
497
498
499
|
# File 'lib/suspenders/app_builder.rb', line 495
def
replace_in_file 'config/routes.rb',
/Rails\.application\.routes\.draw do.*end/m,
"Rails.application.routes.draw do\nend"
end
|
#replace_flash_javascript_file ⇒ Object
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_used ⇒ Object
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_method ⇒ Object
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_rspec ⇒ Object
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_forego ⇒ Object
352
353
354
|
# File 'lib/suspenders/app_builder.rb', line 352
def set_up_forego
copy_file "Procfile", "Procfile"
end
|
#set_up_hound ⇒ Object
127
128
129
|
# File 'lib/suspenders/app_builder.rb', line 127
def set_up_hound
copy_file "hound.yml", ".hound.yml"
end
|
#setup_asset_host ⇒ Object
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_bundler_audit ⇒ Object
445
446
447
448
|
# File 'lib/suspenders/app_builder.rb', line 445
def setup_bundler_audit
copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake"
append_file "Rakefile", %{\ntask default: "bundler:audit"\n}
end
|
#setup_colors_stylesheet ⇒ Object
363
364
365
366
367
368
369
|
# File 'lib/suspenders/app_builder.rb', line 363
def setup_colors_stylesheet
copy_file "_colors.scss", "app/assets/stylesheets/variables/_colors.scss"
inject_into_file "app/assets/stylesheets/application.scss",
"\n// ==== Variables\n@import \"variables/colors\";",
after: '@import "font-awesome";'
end
|
#setup_default_directories ⇒ Object
379
380
381
382
383
384
385
386
387
388
389
390
391
|
# File 'lib/suspenders/app_builder.rb', line 379
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
# File 'lib/suspenders/app_builder.rb', line 505
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_stylesheet ⇒ Object
371
372
373
374
375
376
377
|
# File 'lib/suspenders/app_builder.rb', line 371
def setup_flash_stylesheet
copy_file "_flash.scss", "app/assets/stylesheets/componentes/_flash.scss"
inject_into_file "app/assets/stylesheets/application.scss",
"\n// ==== Components\n@import \"components/flash\"; ",
after: '@import "variables/colors";'
end
|
#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
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_segment ⇒ Object
440
441
442
443
|
# File 'lib/suspenders/app_builder.rb', line 440
def setup_segment
copy_file '_analytics.html.erb',
'app/views/application/_analytics.html.erb'
end
|
#setup_spring ⇒ Object
450
451
452
|
# File 'lib/suspenders/app_builder.rb', line 450
def setup_spring
bundle_command "exec spring binstub --all"
end
|
#setup_staging_environment ⇒ Object
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_stylesheets ⇒ Object
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
|
521
522
523
524
|
# File 'lib/suspenders/app_builder.rb', line 521
def
config = "config.secret_key"
("config/initializers/devise.rb", config)
end
|
#use_postgres_config_template ⇒ Object
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
|