Class: Shoelaces::AppBuilder

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

Constant Summary collapse

@@port_number =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #configure_environment, #replace_in_file, #uncomment_in_file

Class Method Details

.set_port_number(number) ⇒ Object



6
7
8
# File 'lib/shoelaces/app_builder.rb', line 6

def self.set_port_number(number)
  @@port_number = number
end

Instance Method Details

#add_imagesObject



134
135
136
# File 'lib/shoelaces/app_builder.rb', line 134

def add_images
  copy_file 'noise.png', 'app/assets/images/noise.png'
end

#add_static_pagesObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/shoelaces/app_builder.rb', line 138

def add_static_pages
  template 'home.html.erb.erb',
    'app/views/pages/home.html.erb',
    force: true
  template 'about.html.erb.erb',
    'app/views/pages/about.html.erb',
    force: true
  template 'contact.html.erb.erb',
    'app/views/pages/contact.html.erb',
    force: true
end

#configure_action_mailerObject



259
260
261
262
263
264
# File 'lib/shoelaces/app_builder.rb', line 259

def configure_action_mailer
  action_mailer_host 'development', "localhost:#{port_number}"
  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



238
239
240
# File 'lib/shoelaces/app_builder.rb', line 238

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

#configure_background_jobs_for_rspecObject



233
234
235
236
# File 'lib/shoelaces/app_builder.rb', line 233

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

#configure_generatorsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shoelaces/app_builder.rb', line 42

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_for_development_environmentObject



229
230
231
# File 'lib/shoelaces/app_builder.rb', line 229

def configure_i18n_for_development_environment
  raise_on_missing_translations_in("development")
end

#configure_i18n_for_test_environmentObject



224
225
226
227
# File 'lib/shoelaces/app_builder.rb', line 224

def configure_i18n_for_test_environment
  copy_file 'i18n.rb', 'spec/support/i18n.rb'
  raise_on_missing_translations_in("test")
end

#configure_newrelicObject



63
64
65
# File 'lib/shoelaces/app_builder.rb', line 63

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

#configure_rack_timeoutObject



255
256
257
# File 'lib/shoelaces/app_builder.rb', line 255

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

#configure_rspecObject



215
216
217
218
# File 'lib/shoelaces/app_builder.rb', line 215

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

#configure_smtpObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/shoelaces/app_builder.rb', line 67

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



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

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

#configure_time_formatsObject



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

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

#configure_time_zoneObject



242
243
244
245
246
247
248
# File 'lib/shoelaces/app_builder.rb', line 242

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



220
221
222
# File 'lib/shoelaces/app_builder.rb', line 220

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

#configure_unicornObject



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

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

#copy_miscellaneous_filesObject



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

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

#create_application_layoutObject



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

def create_application_layout
  template 'shoelaces_layout.html.erb.erb',
    'app/views/layouts/application.html.erb',
    force: true
  template 'shoelaces_layout_header.html.erb.erb',
    'app/views/layouts/_header.html.erb',
    force: true
  template 'shoelaces_layout_footer.html.erb.erb',
    'app/views/layouts/_footer.html.erb',
    force: true
end

#create_databaseObject



188
189
190
# File 'lib/shoelaces/app_builder.rb', line 188

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

#create_github_repo(repo_name) ⇒ Object



363
364
365
366
# File 'lib/shoelaces/app_builder.rb', line 363

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

#create_heroku_appsObject



324
325
326
327
328
329
# File 'lib/shoelaces/app_builder.rb', line 324

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



126
127
128
# File 'lib/shoelaces/app_builder.rb', line 126

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



130
131
132
# File 'lib/shoelaces/app_builder.rb', line 130

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

#customize_error_pagesObject



377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/shoelaces/app_builder.rb', line 377

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



396
397
398
# File 'lib/shoelaces/app_builder.rb', line 396

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

#enable_database_cleanerObject



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

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

#enable_rack_deflaterObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/shoelaces/app_builder.rb', line 83

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



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

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



274
275
276
# File 'lib/shoelaces/app_builder.rb', line 274

def generate_rspec
  generate 'rspec:install'
end

#generate_simple_formObject



278
279
280
# File 'lib/shoelaces/app_builder.rb', line 278

def generate_simple_form
  generate 'simple_form:install --bootstrap'
end

#gitignore_filesObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/shoelaces/app_builder.rb', line 303

def gitignore_files
  remove_file '.gitignore'
  copy_file 'shoelaces_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



320
321
322
# File 'lib/shoelaces/app_builder.rb', line 320

def init_git
  run 'git init'
end

#join_heroku_app(environment) ⇒ Object



346
347
348
349
350
351
352
353
354
355
# File 'lib/shoelaces/app_builder.rb', line 346

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



38
39
40
# File 'lib/shoelaces/app_builder.rb', line 38

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

#provide_setup_scriptObject



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

def provide_setup_script
  template 'bin_setup.erb', 'bin/setup', port_number: port_number
  run 'chmod a+x bin/setup'
end

#raise_on_delivery_errorsObject



14
15
16
17
# File 'lib/shoelaces/app_builder.rb', line 14

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/shoelaces/app_builder.rb', line 19

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



10
11
12
# File 'lib/shoelaces/app_builder.rb', line 10

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

#remove_routes_comment_linesObject



390
391
392
393
394
# File 'lib/shoelaces/app_builder.rb', line 390

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


162
163
164
165
166
# File 'lib/shoelaces/app_builder.rb', line 162

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

#replace_gemfileObject



192
193
194
195
# File 'lib/shoelaces/app_builder.rb', line 192

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

#set_heroku_rails_secretsObject



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

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



331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/shoelaces/app_builder.rb', line 331

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



197
198
199
# File 'lib/shoelaces/app_builder.rb', line 197

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

#set_up_factory_girl_for_rspecObject



59
60
61
# File 'lib/shoelaces/app_builder.rb', line 59

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

#setup_asset_hostObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/shoelaces/app_builder.rb', line 94

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/initializers/assets.rb',
    "config.assets.version = '1.0'",
    'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'

  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_bootstrap_javascriptObject



168
169
170
171
172
173
174
175
176
177
# File 'lib/shoelaces/app_builder.rb', line 168

def setup_bootstrap_javascript
  bootstrap_javascript = "//= require bootstrap\n  RUBY\n  inject_into_file(\n    'app/assets/javascripts/application.js',\n    bootstrap_javascript,\n    before: \"//= require_tree .\"\n  )\nend\n"

#setup_default_rake_taskObject



400
401
402
403
404
# File 'lib/shoelaces/app_builder.rb', line 400

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

#setup_foremanObject



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

def setup_foreman
  copy_file 'sample.env', '.sample.env'
  copy_file 'Procfile', 'Procfile'
end

#setup_guardObject



291
292
293
# File 'lib/shoelaces/app_builder.rb', line 291

def setup_guard
  copy_file 'Guardfile', 'Guardfile'
end

#setup_heroku_specific_gemsObject



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

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

#setup_secret_tokenObject



122
123
124
# File 'lib/shoelaces/app_builder.rb', line 122

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

#setup_segment_ioObject



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

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

#setup_staging_environmentObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/shoelaces/app_builder.rb', line 108

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



295
296
297
298
299
300
301
# File 'lib/shoelaces/app_builder.rb', line 295

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

#use_high_voltage_config_templateObject



184
185
186
# File 'lib/shoelaces/app_builder.rb', line 184

def use_high_voltage_config_template
  copy_file 'high_voltage.rb', 'config/initializers/high_voltage.rb'
end

#use_postgres_config_templateObject



179
180
181
182
# File 'lib/shoelaces/app_builder.rb', line 179

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