Class: Jetfuel::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/jetfuel/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #configure_environment, #replace_in_file

Instance Method Details

#add_bootstrap_jsObject



145
146
147
148
# File 'lib/jetfuel/app_builder.rb', line 145

def add_bootstrap_js
  inject_into_file 'app/assets/javascripts/application.js', "//= require bootstrap\n",
    after: /\/\/= require jquery_ujs\n/
end

#configure_action_mailerObject



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

def configure_action_mailer
  action_mailer_host 'development', "#{app_name}.local"
  action_mailer_host 'test', 'www.example.com'
  action_mailer_host 'staging', "staging.#{app_name}.com"
  action_mailer_host 'production', "#{app_name}.com"
end

#configure_action_mailer_in_specsObject



200
201
202
# File 'lib/jetfuel/app_builder.rb', line 200

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

#configure_background_jobs_for_rspecObject



195
196
197
198
# File 'lib/jetfuel/app_builder.rb', line 195

def configure_background_jobs_for_rspec
  copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
  run 'bundle exec rails g delayed_job:active_record'
end

#configure_generatorsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jetfuel/app_builder.rb', line 37

def configure_generators
  config = "config.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_in_specsObject



191
192
193
# File 'lib/jetfuel/app_builder.rb', line 191

def configure_i18n_in_specs
  copy_file 'i18n.rb', 'spec/support/i18n.rb'
end

#configure_newrelicObject



58
59
60
# File 'lib/jetfuel/app_builder.rb', line 58

def configure_newrelic
  template 'newrelic.yml.erb', 'config/newrelic.yml'
end

#configure_rack_timeoutObject



217
218
219
# File 'lib/jetfuel/app_builder.rb', line 217

def configure_rack_timeout
  copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
end

#configure_rspecObject



182
183
184
185
# File 'lib/jetfuel/app_builder.rb', line 182

def configure_rspec
  remove_file 'spec/spec_helper.rb'
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
end

#configure_smtpObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jetfuel/app_builder.rb', line 62

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_featuresObject



177
178
179
180
# File 'lib/jetfuel/app_builder.rb', line 177

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

#configure_time_formatsObject



212
213
214
215
# File 'lib/jetfuel/app_builder.rb', line 212

def configure_time_formats
  remove_file 'config/locales/en.yml'
  copy_file 'config_locales_en.yml', 'config/locales/en.yml'
end

#configure_time_zoneObject



204
205
206
207
208
209
210
# File 'lib/jetfuel/app_builder.rb', line 204

def configure_time_zone
  config = "config.active_record.default_timezone = :utc\n\n  RUBY\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#configure_travisObject



187
188
189
# File 'lib/jetfuel/app_builder.rb', line 187

def configure_travis
  template 'travis.yml.erb', '.travis.yml'
end

#configure_unicornObject



240
241
242
# File 'lib/jetfuel/app_builder.rb', line 240

def configure_unicorn
  copy_file 'unicorn.rb', 'config/unicorn.rb'
end

#copy_miscellaneous_filesObject



350
351
352
# File 'lib/jetfuel/app_builder.rb', line 350

def copy_miscellaneous_files
  copy_file 'errors.rb', 'config/initializers/errors.rb'
end

#create_application_layoutObject



133
134
135
136
137
# File 'lib/jetfuel/app_builder.rb', line 133

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

#create_databaseObject



155
156
157
# File 'lib/jetfuel/app_builder.rb', line 155

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

#create_devise_userObject



275
276
277
278
# File 'lib/jetfuel/app_builder.rb', line 275

def create_devise_user
  run 'bundle exec rails g devise User'
  run 'rake db:migrate'
end

#create_github_repo(repo_name) ⇒ Object



340
341
342
343
# File 'lib/jetfuel/app_builder.rb', line 340

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

#create_heroku_appsObject



301
302
303
304
305
306
# File 'lib/jetfuel/app_builder.rb', line 301

def create_heroku_apps
  path_addition = override_path_for_tests
  run "#{path_addition} heroku create #{app_name}-production --remote=production"
  run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
  run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
end

#create_partials_directoryObject



121
122
123
# File 'lib/jetfuel/app_builder.rb', line 121

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



125
126
127
# File 'lib/jetfuel/app_builder.rb', line 125

def create_shared_flashes
  copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
end

#create_shared_javascriptsObject



129
130
131
# File 'lib/jetfuel/app_builder.rb', line 129

def create_shared_javascripts
  copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
end

#customize_error_pagesObject



354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/jetfuel/app_builder.rb', line 354

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



373
374
375
# File 'lib/jetfuel/app_builder.rb', line 373

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

#enable_database_cleanerObject



173
174
175
# File 'lib/jetfuel/app_builder.rb', line 173

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

#enable_rack_deflaterObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/jetfuel/app_builder.rb', line 78

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 'config/environments/production.rb', config,\n    :after => \"config.serve_static_assets = false\\n\"\nend\n"

#fix_i18n_deprecation_warningObject



228
229
230
231
232
233
234
# File 'lib/jetfuel/app_builder.rb', line 228

def fix_i18n_deprecation_warning
  config = "config.i18n.enforce_available_locales = true\n\n  RUBY\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#generate_rspecObject



236
237
238
# File 'lib/jetfuel/app_builder.rb', line 236

def generate_rspec
  run 'bundle exec rails g rspec:install'
end

#gitignore_filesObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/jetfuel/app_builder.rb', line 280

def gitignore_files
  remove_file '.gitignore'
  copy_file 'suspenders_gitignore', '.gitignore'
  [
    'app/views/pages',
    'spec/lib',
    'spec/controllers',
    'spec/helpers',
    'spec/support/matchers',
    'spec/support/mixins',
    'spec/support/shared_examples'
  ].each do |dir|
    run "mkdir #{dir}"
    run "touch #{dir}/.keep"
  end
end

#init_gitObject



297
298
299
# File 'lib/jetfuel/app_builder.rb', line 297

def init_git
  run 'git init'
end

#install_deviseObject



268
269
270
271
272
273
# File 'lib/jetfuel/app_builder.rb', line 268

def install_devise
  run 'bundle exec rails g devise:install'
  remove_file 'config/initializers/devise.rb'
  copy_file 'devise.rb',
    'config/initializers/devise.rb'
end

#install_leatherObject



258
259
260
# File 'lib/jetfuel/app_builder.rb', line 258

def install_leather
  run "bundle exec rails g leather:install"
end

#join_heroku_app(environment) ⇒ Object



323
324
325
326
327
328
329
330
331
332
# File 'lib/jetfuel/app_builder.rb', line 323

def join_heroku_app(environment)
  heroku_app_name = "#{app_name}-#{environment}"
  "if heroku join --app \#{heroku_app_name} &> /dev/null; then\n  echo 'You are a collaborator on the \"\#{heroku_app_name}\" Heroku app'\nelse\n  echo 'Ask for access to the \"\#{heroku_app_name}\" Heroku app'\nfi\n  SHELL\nend\n"

#provide_dev_prime_taskObject



33
34
35
# File 'lib/jetfuel/app_builder.rb', line 33

def provide_dev_prime_task
  copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake'
end

#provide_setup_scriptObject



28
29
30
31
# File 'lib/jetfuel/app_builder.rb', line 28

def provide_setup_script
  copy_file 'bin_setup', 'bin/setup'
  run 'chmod a+x bin/setup'
end

#raise_on_delivery_errorsObject



9
10
11
12
# File 'lib/jetfuel/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_parametersObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jetfuel/app_builder.rb', line 14

def raise_on_unpermitted_parameters
  action_on_unpermitted_parameters = "\n  # Raise an ActionController::UnpermittedParameters exception when\n  # a parameter is not explcitly permitted but is passed anyway.\n  config.action_controller.action_on_unpermitted_parameters = :raise\n  RUBY\n  inject_into_file(\n    \"config/environments/development.rb\",\n    action_on_unpermitted_parameters,\n    before: \"\\nend\"\n  )\nend\n"

#readmeObject



5
6
7
# File 'lib/jetfuel/app_builder.rb', line 5

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

#remove_routes_comment_linesObject



367
368
369
370
371
# File 'lib/jetfuel/app_builder.rb', line 367

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


139
140
141
142
143
# File 'lib/jetfuel/app_builder.rb', line 139

def remove_turbolinks
  replace_in_file 'app/assets/javascripts/application.js',
    /\/\/= require turbolinks\n/,
    ''
end

#replace_gemfileObject



159
160
161
162
# File 'lib/jetfuel/app_builder.rb', line 159

def replace_gemfile
  remove_file 'Gemfile'
  template 'Gemfile.erb', 'Gemfile'
end

#set_heroku_rails_secretsObject



334
335
336
337
338
# File 'lib/jetfuel/app_builder.rb', line 334

def set_heroku_rails_secrets
  path_addition = override_path_for_tests
  run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=staging"
  run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=production"
end

#set_heroku_remotesObject



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/jetfuel/app_builder.rb', line 308

def set_heroku_remotes
  remotes = "\n# Set up staging and production git remotes.\ngit remote add staging [email protected]:\#{app_name}-staging.git || true\ngit remote add production [email protected]:\#{app_name}-production.git || true\n\n# Join 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_ruby_to_version_being_usedObject



164
165
166
# File 'lib/jetfuel/app_builder.rb', line 164

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

#set_up_factory_girl_for_rspecObject



54
55
56
# File 'lib/jetfuel/app_builder.rb', line 54

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

#setup_asset_hostObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/jetfuel/app_builder.rb', line 89

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')"

  replace_in_file 'config/environments/production.rb',
    "config.assets.version = '1.0'",
    "config.assets.version = ENV.fetch('ASSETS_VERSION')"

  replace_in_file 'config/environments/production.rb',
    'config.serve_static_assets = false',
    'config.static_cache_control = "public, max-age=#{1.year.to_i}"'
end

#setup_default_rake_taskObject



377
378
379
380
381
# File 'lib/jetfuel/app_builder.rb', line 377

def setup_default_rake_task
  append_file 'Rakefile' do
    "task(:default).clear\ntask :default => [:spec]\n"
  end
end

#setup_foremanObject



244
245
246
247
248
# File 'lib/jetfuel/app_builder.rb', line 244

def setup_foreman
  copy_file 'sample.env', '.env'
  replace_in_file ".env", /development_secret/, generate_secret
  copy_file 'Procfile', 'Procfile'
end

#setup_helpersObject



262
263
264
265
266
# File 'lib/jetfuel/app_builder.rb', line 262

def setup_helpers
  remove_file 'app/helpers/application_helper.rb'
  copy_file 'application_helper.rb',
    'app/helpers/application_helper.rb'
end

#setup_heroku_specific_gemsObject



168
169
170
171
# File 'lib/jetfuel/app_builder.rb', line 168

def setup_heroku_specific_gems
  inject_into_file 'Gemfile', "\n\s\sgem 'rails_12factor'",
    after: /group :staging, :production do/
end

#setup_secret_tokenObject



117
118
119
# File 'lib/jetfuel/app_builder.rb', line 117

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

#setup_segment_ioObject



345
346
347
348
# File 'lib/jetfuel/app_builder.rb', line 345

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

#setup_staging_environmentObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jetfuel/app_builder.rb', line 103

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_stylesheetsObject



250
251
252
253
254
255
256
# File 'lib/jetfuel/app_builder.rb', line 250

def setup_stylesheets
  remove_file 'app/assets/stylesheets/application.css'
  copy_file 'application.css.scss',
    'app/assets/stylesheets/application.css.scss'
  copy_file 'flashes.css.scss',
    'app/assets/stylesheets/flashes.css.scss'
end

#use_postgres_config_templateObject



150
151
152
153
# File 'lib/jetfuel/app_builder.rb', line 150

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