Class: Suspenders::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
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

#configure_action_mailerObject



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

def configure_action_mailer
  action_mailer_host "development", %{"localhost:#{port}"}
  action_mailer_host "test", %{"www.example.com"}
  action_mailer_host "staging", %{ENV['WEB_ADDRESS_EXT']}
  action_mailer_host "production", %{ENV['WEB_ADDRESS_EXT']}
end

#configure_action_mailer_in_specsObject



185
186
187
# File 'lib/suspenders/app_builder.rb', line 185

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

#configure_circleciObject



167
168
169
# File 'lib/suspenders/app_builder.rb', line 167

def configure_circleci
  template 'circle.yml', 'circle.yml'
end

#configure_generatorsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/suspenders/app_builder.rb', line 39

def configure_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
end

#configure_i18n_for_missing_translationsObject



175
176
177
178
# File 'lib/suspenders/app_builder.rb', line 175

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

#configure_i18n_for_test_environmentObject



171
172
173
# File 'lib/suspenders/app_builder.rb', line 171

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

#configure_i18n_tasksObject



180
181
182
183
# File 'lib/suspenders/app_builder.rb', line 180

def configure_i18n_tasks
  run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/"
  copy_file "config_i18n_tasks.yml", "config/i18n-tasks.yml"
end

#configure_mandrillObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/suspenders/app_builder.rb', line 61

def configure_mandrill
  copy_file 'mandrill.rb', 'config/initializers/mandrill.rb'

  config = <<-RUBY
  config.action_mailer.delivery_method = :mandrill
  RUBY

  inject_into_file 'config/environments/production.rb', config,
    :after => 'config.action_mailer.raise_delivery_errors = false'
end

#configure_rack_timeoutObject



194
195
196
197
198
199
200
# File 'lib/suspenders/app_builder.rb', line 194

def configure_rack_timeout
  rack_timeout_config = <<-RUBY
Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i
  RUBY

  append_file "config/environments/production.rb", rack_timeout_config
end

#configure_rspecObject



160
161
162
163
164
165
# File 'lib/suspenders/app_builder.rb', line 160

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



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

def configure_simple_form
  bundle_command "exec rails generate simple_form:install"
end

#configure_spec_support_featuresObject



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

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

#configure_time_formatsObject



189
190
191
192
# File 'lib/suspenders/app_builder.rb', line 189

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

#copy_miscellaneous_filesObject



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

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

#create_application_layoutObject



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

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

#create_databaseObject



138
139
140
# File 'lib/suspenders/app_builder.rb', line 138

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

#create_github_repo(repo_name) ⇒ Object



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

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

#create_partials_directoryObject



114
115
116
# File 'lib/suspenders/app_builder.rb', line 114

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



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

def create_shared_flashes
  copy_file "_flashes.html.erb", "app/views/application/_flashes.html.erb"
  copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb"
end

#create_shared_javascriptsObject



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

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

#customize_error_pagesObject



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/suspenders/app_builder.rb', line 277

def customize_error_pages
  meta_tags =<<-EOS
  <meta charset="utf-8" />
  <meta name="ROBOTS" content="NOODP" />
  <meta name="viewport" content="initial-scale=1" />
  EOS

  %w(500 404 422).each do |page|
    inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
    replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
  end
end

#disable_xml_paramsObject



296
297
298
# File 'lib/suspenders/app_builder.rb', line 296

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

#disallow_wrapping_parametersObject



110
111
112
# File 'lib/suspenders/app_builder.rb', line 110

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

#enable_database_cleanerObject



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

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

#enable_rack_deflaterObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/suspenders/app_builder.rb', line 72

def enable_rack_deflater
  config = <<-RUBY

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

  inject_into_file(
    "config/environments/production.rb",
    config,
    after: serve_static_files_line
  )
end

#fix_i18n_deprecation_warningObject



213
214
215
216
217
218
219
# File 'lib/suspenders/app_builder.rb', line 213

def fix_i18n_deprecation_warning
  config = <<-RUBY
config.i18n.enforce_available_locales = true
  RUBY

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

#generate_rspecObject



221
222
223
# File 'lib/suspenders/app_builder.rb', line 221

def generate_rspec
  generate 'rspec:install'
end

#gitignore_filesObject



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/suspenders/app_builder.rb', line 240

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



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

def init_git
  run 'git init'
end

#install_bittersObject



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

def install_bitters
  run "bitters install --path app/assets/stylesheets"
end

#provide_dev_prime_taskObject



35
36
37
# File 'lib/suspenders/app_builder.rb', line 35

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

#provide_setup_scriptObject



30
31
32
33
# File 'lib/suspenders/app_builder.rb', line 30

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

#raise_on_delivery_errorsObject



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



22
23
24
25
26
27
28
# File 'lib/suspenders/app_builder.rb', line 22

def raise_on_unpermitted_parameters
  config = <<-RUBY
config.action_controller.action_on_unpermitted_parameters = :raise
  RUBY

  inject_into_class "config/application.rb", "Application", config
end

#readmeObject



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

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

#remove_routes_comment_linesObject



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

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_gemfileObject



142
143
144
145
# File 'lib/suspenders/app_builder.rb', line 142

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

#set_ruby_to_version_being_usedObject



147
148
149
# File 'lib/suspenders/app_builder.rb', line 147

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

#set_test_delivery_methodObject



14
15
16
17
18
19
20
# File 'lib/suspenders/app_builder.rb', line 14

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

#set_up_factory_girl_for_rspecObject



57
58
59
# File 'lib/suspenders/app_builder.rb', line 57

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

#setup_bundler_auditObject



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

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_rake_taskObject



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/suspenders/app_builder.rb', line 300

def setup_default_rake_task
  append_file 'Rakefile' do
    <<-EOS
task(:default).clear
task default: [:spec]

if defined? RSpec
  task(:spec).clear
  RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
  end
end
    EOS
  end
end

#setup_foremanObject



225
226
227
228
# File 'lib/suspenders/app_builder.rb', line 225

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

#setup_secret_tokenObject



100
101
102
103
104
105
106
107
108
# File 'lib/suspenders/app_builder.rb', line 100

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

  inject_into_file(
    "config/environments/production.rb",
    '  config.active_record.dump_schema_after_migration = false',
    after: 'config.active_record.dump_schema_after_migration = false'
  )
end

#setup_staging_environmentObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/suspenders/app_builder.rb', line 86

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

  config = <<-RUBY

Rails.application.configure do
  config.secret_key_base = ENV["SECRET_KEY_BASE"]
end
  RUBY

  append_file staging_file, config
end

#setup_stylesheetsObject



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

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

#use_postgres_config_templateObject



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

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