Class: RoughDraft::RailsBuilder

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

Instance Method Summary collapse

Methods included from Actions

#copy_source_file, #git_commit

Instance Method Details

#appObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rough_draft/rails_builder.rb', line 20

def app
  super

  remove_file                    'app/controllers/concerns'
  remove_file                    'app/models/concerns'

  empty_directory_with_keep_file 'app/assets/fonts'

  empty_directory_with_keep_file 'app/assets/images/backgrounds'
  empty_directory_with_keep_file 'app/assets/images/decorations'
  empty_directory_with_keep_file 'app/assets/images/emails'
  empty_directory_with_keep_file 'app/assets/images/icons'
  empty_directory_with_keep_file 'app/assets/images/logos'
  empty_directory_with_keep_file 'app/assets/images/placeholders'
  empty_directory_with_keep_file 'app/assets/images/text'
  empty_directory_with_keep_file 'app/assets/images/ui'
end

#bugsnagObject



332
333
334
335
336
337
# File 'lib/rough_draft/rails_builder.rb', line 332

def bugsnag
  copy_source_file                'config/initializers/bugsnag.rb'
  template                        'config/settings/bugsnag.yml.erb', 'config/settings/bugsnag.yml'

  git_commit                      'Configure BugSnag'
end

#chamberObject



250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/rough_draft/rails_builder.rb', line 250

def chamber
  uncomment_lines                 'Gemfile', /chamber/
  bundle_command                  'update'
  run                             "cd #{destination_root} && chamber init"

  git_commit                      'Configure Chamber'

  remove_file                     'config/secrets.yml'
  create_file                     'config/settings.yml', '', force: true
  empty_directory                 'config/settings'
  template                        'config/settings/http.yml.erb', 'config/settings/http.yml'

  git_commit                      'Setup default settings files'
end

#code_climateObject



326
327
328
329
330
# File 'lib/rough_draft/rails_builder.rb', line 326

def code_climate
  template                        'config/settings/code_climate.yml.erb', 'config/settings/code_climate.yml'

  git_commit                      'Configure CodeClimate'
end

#configObject



44
45
46
47
48
49
50
# File 'lib/rough_draft/rails_builder.rb', line 44

def config
  super

  remove_commented_route_lines

  staging_environment
end

#database_backupObject



349
350
351
352
353
# File 'lib/rough_draft/rails_builder.rb', line 349

def database_backup
  copy_source_file                'lib/tasks/db-backup.rake'

  git_commit                      'Setup Database Backup Tasks'
end

#database_seedingObject



339
340
341
342
343
344
345
346
347
# File 'lib/rough_draft/rails_builder.rb', line 339

def database_seeding
  remove_file                     'db/seeds.rb'

  copy_source_file                'lib/tasks/db-seed.rake'
  copy_source_file                'db/seed.rb'
  copy_source_file                'db/samplize.rb'

  git_commit                      'Setup Database Seeding and Sampling Tasks'
end

#database_ymlObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/rough_draft/rails_builder.rb', line 52

def database_yml
  if options[:database] == 'postgresql'
    template 'config/database-example.yml.erb', 'config/database.yml'
  else
    super
  end

  copy_file         "#{destination_root}/config/database.yml",  'config/database-example.yml'
  copy_source_file  'config/database-travis.yml'
end

#dbObject



63
64
65
66
67
# File 'lib/rough_draft/rails_builder.rb', line 63

def db
  super

  bundle_command 'exec rake db:drop:all db:create:all db:migrate db:test:prepare'
end

#deviseObject



236
237
238
239
240
241
# File 'lib/rough_draft/rails_builder.rb', line 236

def devise
  route                           "root :to => 'devise/sessions#new'"
  comment_lines                   'config/routes.rb', /root/

  git_commit                      'Add Default (Commented) Devise Route'
end

#dirty_urlObject



277
278
279
280
281
282
# File 'lib/rough_draft/rails_builder.rb', line 277

def dirty_url
  uncomment_lines                 'Gemfile', /dirty_url/
  bundle_command                  'update'

  git_commit                      'Install dirty_url for default_url_options'
end

#disable_generatorsObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rough_draft/rails_builder.rb', line 138

def disable_generators
  config = <<-RUBY
  config.generators do |generate|
    generate.helper false
    generate.javascript_engine false
    generate.request_specs false
    generate.routing_specs false
    generate.stylesheets false
    generate.test_framework :rspec
    generate.view_specs false
  end

  RUBY

  inject_into_class               'config/application.rb', 'Application', config

  git_commit                      'Disable generators'
end


210
211
212
213
214
215
216
# File 'lib/rough_draft/rails_builder.rb', line 210

def disable_turbolinks
  gsub_file                       'app/assets/javascripts/application.js',
                                  %r{//= require turbolinks\n},
                                  ''

  git_commit                      'Disable Turbolinks'
end

#environment_bannersObject



90
91
92
93
94
95
96
97
# File 'lib/rough_draft/rails_builder.rb', line 90

def environment_banners
  empty_directory   'app/assets/images/decorations/environment-banners'
  copy_source_file  'app/assets/images/decorations/environment-banners/development-banner.png'
  copy_source_file  'app/assets/images/decorations/environment-banners/test-banner.png'
  copy_source_file  'app/assets/images/decorations/environment-banners/staging-banner.png'

  git_commit        'Add Environment Banners'
end

#factoriesObject



170
171
172
173
174
175
# File 'lib/rough_draft/rails_builder.rb', line 170

def factories
  copy_source_file                'spec/factories/user.rb'
  copy_source_file                'spec/factories/all_factories_are_valid_spec.rb'

  git_commit                      'Setup Factories'
end

#foremanObject



296
297
298
299
300
# File 'lib/rough_draft/rails_builder.rb', line 296

def foreman
  copy_source_file                'Procfile'

  git_commit                      'Configure Foreman'
end

#gemfileObject



12
13
14
# File 'lib/rough_draft/rails_builder.rb', line 12

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

#git_finalizeObject



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

def git_finalize
  git_commit        'Completed Template Initialization'
  git               :checkout => 'master --quiet'
  git               :merge    => '--no-ff rough-draft --quiet --no-edit'
  git               :branch   => '-D rough-draft --quiet'
  git               :push     => 'origin master'
end

#git_repoObject



69
70
71
72
73
74
# File 'lib/rough_draft/rails_builder.rb', line 69

def git_repo
  git               :init     => '--quiet'
  git_commit        'Initial App Generation'
  git               :branch   => 'rough-draft --quiet'
  git               :checkout => 'rough-draft --quiet'
end

#github_repo(repo_name) ⇒ Object



368
369
370
371
372
373
# File 'lib/rough_draft/rails_builder.rb', line 368

def github_repo(repo_name)
  run                             "hub create #{repo_name}"
  git                             remote: 'remove origin'
  git                             remote: "add -t master origin [email protected]:#{repo_name}.git"
  git                             push:   "--quiet --set-upstream origin master"
end

#gitignoreObject



16
17
18
# File 'lib/rough_draft/rails_builder.rb', line 16

def gitignore
  copy_file 'kompanee-gitignore', '.gitignore'
end

#helpersObject



224
225
226
227
228
# File 'lib/rough_draft/rails_builder.rb', line 224

def helpers
  remove_file                     'app/helpers/application_helper.rb'

  git_commit                      'Remove uneeded helper'
end

#heroku_appsObject



382
383
384
385
386
# File 'lib/rough_draft/rails_builder.rb', line 382

def heroku_apps
  run "heroku create #{heroku_production_app_name} --remote=production"
  run "heroku create #{heroku_staging_app_name} --remote=staging"
  run "heroku config:add RACK_ENV=staging RAILS_ENV=staging --app=#{heroku_staging_app_name} --remote=staging"
end

#heroku_configObject



388
389
390
# File 'lib/rough_draft/rails_builder.rb', line 388

def heroku_config
  template                        'config/settings/heroku.yml.erb', 'config/settings/heroku.yml'
end

#heroku_remotesObject



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/rough_draft/rails_builder.rb', line 392

def heroku_remotes
  remotes = <<-RUBY

# Set up staging and production git remotes
git remote add staging [email protected]:#{heroku_staging_app_name}.git
git remote add production [email protected]:#{heroku_production_app_name}.git
  RUBY

  append_file                     'bin/setup', remotes

  git remote: "add staging [email protected]:#{heroku_staging_app_name}.git"
  git remote: "add production [email protected]:#{heroku_production_app_name}.git"

  git_commit                      'Add staging and production remotes to setup script'
end

#heroku_specific_gemsObject



375
376
377
378
379
380
# File 'lib/rough_draft/rails_builder.rb', line 375

def heroku_specific_gems
  uncomment_lines                 'Gemfile', /rails_12factor/
  bundle_command                  'update'

  git_commit                      'Add Heroku-specific gems'
end

#human_textObject



218
219
220
221
222
# File 'lib/rough_draft/rails_builder.rb', line 218

def human_text
  template                        'public/humans.txt.erb', 'public/humans.txt'

  git_commit                      'Add human.txt'
end

#i18nObject



265
266
267
268
269
# File 'lib/rough_draft/rails_builder.rb', line 265

def i18n
  template                        'config/initializers/i18n.rb.erb', 'config/initializers/i18n.rb'

  git_commit                      'Configure i18n'
end

#localesObject



362
363
364
365
366
# File 'lib/rough_draft/rails_builder.rb', line 362

def locales
  copy_file                       'config/locales/date-formats-en.yml', 'config/locales/en.yml', force: true

  git_commit                      'Add default date/time formats'
end

#mail_safeObject



302
303
304
305
306
# File 'lib/rough_draft/rails_builder.rb', line 302

def mail_safe
  copy_source_file                'config/initializers/mail_safe.rb'

  git_commit                      'Configure Mail Safe'
end

#public_directoryObject



38
39
40
41
42
# File 'lib/rough_draft/rails_builder.rb', line 38

def public_directory
  super

  remove_file 'public/favicon.ico'
end

#rack_deflatorObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rough_draft/rails_builder.rb', line 184

def rack_deflator
  config = <<-RUBY

# Enable deflate / gzip compression of controller-generated responses
config.middleware.use Rack::Deflater

  RUBY

  inject_into_file  'config/environments/production.rb',
                    config.chomp,
                    after: "config.serve_static_assets = false\n"

  staging_environment

  git_commit                      'Setup Rack Deflator'
end

#rack_timeoutObject



284
285
286
287
288
# File 'lib/rough_draft/rails_builder.rb', line 284

def rack_timeout
  copy_source_file                'config/initializers/rack_timeout.rb'

  git_commit                      'Configure Rack Timeout'
end

#raise_on_delivery_errorsObject



99
100
101
102
103
104
105
# File 'lib/rough_draft/rails_builder.rb', line 99

def raise_on_delivery_errors
  gsub_file         'config/environments/development.rb',
                    'raise_delivery_errors = false',
                    'raise_delivery_errors = true'

  git_commit        'Raise Delivery Errors in Development'
end

#raise_on_unpermitted_parametersObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rough_draft/rails_builder.rb', line 107

def raise_on_unpermitted_parameters
  action_on_unpermitted_parameters = <<-RUBY


# Raise an ActionController::UnpermittedParameters exception when
# a parameter is not explcitly permitted but is passed anyway.
config.action_controller.action_on_unpermitted_parameters = :raise
  RUBY

  inject_into_file(
    'config/environments/development.rb',
    action_on_unpermitted_parameters.chomp,
    before: "\nend"
  )

  git_commit                      'Raise Errors in Development when unpermitted parameters are used'
end

#readmeObject



8
9
10
# File 'lib/rough_draft/rails_builder.rb', line 8

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

#rspecObject



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rough_draft/rails_builder.rb', line 157

def rspec
  generate                        'rspec:install'

  empty_directory_with_keep_file  'spec/shared_examples'
  empty_directory_with_keep_file  'spec/support'
  empty_directory_with_keep_file  'spec/helpers'
  empty_directory_with_keep_file  'spec/acceptance'

  copy_source_file                'spec/spec_helper.rb'

  git_commit                      'Setup RSpec'
end

#rubocopObject



132
133
134
135
136
# File 'lib/rough_draft/rails_builder.rb', line 132

def rubocop
  copy_file                       'rubocop.yml', '.rubocop.yml'

  git_commit                      'Configure Rubocop'
end

#ruby_versionObject



84
85
86
87
88
# File 'lib/rough_draft/rails_builder.rb', line 84

def ruby_version
  template          'ruby-version.erb', '.ruby-version'

  git_commit        'Add .ruby-version'
end

#secret_tokenObject



408
409
410
411
412
413
# File 'lib/rough_draft/rails_builder.rb', line 408

def secret_token
  gsub_file                       'config/initializers/secret_token.rb', /\s=\s.*/, ' = Chamber.env.application.secret_key'
  template                        'config/settings/application.yml.erb', 'config/settings/application.yml'

  git_commit                      'Secure the Secure Application Token'
end

#secure_configuration_settingsObject



415
416
417
418
419
420
# File 'lib/rough_draft/rails_builder.rb', line 415

def secure_configuration_settings
  run                             "cd #{destination_root} && chamber secure"
  run                             "cd #{destination_root} && chamber travis secure" if github_enabled?

  git_commit                      'Add all configuration settings', :include_settings => true
end

#setup_scriptObject



125
126
127
128
129
130
# File 'lib/rough_draft/rails_builder.rb', line 125

def setup_script
  copy_source_file                'bin/setup'
  chmod                           'bin/setup', 0755

  git_commit                      'Generate setup script'
end

#simple_formObject



243
244
245
246
247
248
# File 'lib/rough_draft/rails_builder.rb', line 243

def simple_form
  generate                        'simple_form:install'
  remove_dir                      'lib/templates'

  git_commit                      'Configure SimpleForm'
end

#skylightObject



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/rough_draft/rails_builder.rb', line 308

def skylight
  bundle_command                  'exec skylight setup'
  template                        'config/initializers/skylight.rb.erb', 'config/initializers/skylight.rb'

  require 'yaml'
  skylight_config               = YAML.load(File.read("#{destination_root}/config/skylight.yml"))
  remove_file                     'config/skylight.yml'
  create_file                     'config/settings/skylight.yml' do
    <<-SKYLIGHT
skylight:
_secure_application:    "#{skylight_config['application']}"
_secure_authentication: "#{skylight_config['authentication']}"
    SKYLIGHT
  end

  git_commit                      'Configure Skylight'
end

#smtpObject



355
356
357
358
359
360
# File 'lib/rough_draft/rails_builder.rb', line 355

def smtp
  copy_source_file                'config/initializers/action_mailer.rb'
  template                        'config/settings/smtp.yml.erb', 'config/settings/smtp.yml'

  git_commit                      'Configure SMTP Options'
end

#stylesheetsObject



201
202
203
204
205
206
207
208
# File 'lib/rough_draft/rails_builder.rb', line 201

def stylesheets
  remove_file                     'app/assets/stylesheets/application.css'

  get                             'http://necolas.github.io/normalize.css/latest/normalize.css', 'app/assets/stylesheets/normalize.scss'
  copy_file                       'app/assets/stylesheets/application.css.scss'

  git_commit                      'Setup Base Stylesheets'
end

#travisObject



177
178
179
180
181
182
# File 'lib/rough_draft/rails_builder.rb', line 177

def travis
  run                             'travis enable'
  template                        'travis.yml.erb', '.travis.yml'

  git_commit                      'Setup Travis CI'
end

#unicornObject



290
291
292
293
294
# File 'lib/rough_draft/rails_builder.rb', line 290

def unicorn
  copy_source_file                'config/unicorn.rb'

  git_commit                      'Configure Unicorn'
end

#viewsObject



230
231
232
233
234
# File 'lib/rough_draft/rails_builder.rb', line 230

def views
  replace_application_layout
  install_shared_partials
  install_maintenance_page
end

#xml_parsingObject



271
272
273
274
275
# File 'lib/rough_draft/rails_builder.rb', line 271

def xml_parsing
  copy_source_file                'config/initializers/xml.rb'

  git_commit                      'Disable XML Parsing'
end