bluebase 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/README.md +67 -12
  4. data/Rakefile +7 -1
  5. data/bin/bluebase +13 -0
  6. data/bin/bundler +16 -0
  7. data/bin/rake +16 -0
  8. data/bin/rspec +16 -0
  9. data/bluebase.gemspec +1 -0
  10. data/lib/bluebase.rb +3 -6
  11. data/lib/bluebase/actions.rb +25 -0
  12. data/lib/bluebase/app_builder.rb +356 -0
  13. data/lib/bluebase/generators/app_generator.rb +129 -0
  14. data/lib/bluebase/version.rb +1 -1
  15. data/spec/fakes/bin/heroku +5 -0
  16. data/spec/fakes/bin/hub +5 -0
  17. data/spec/features/github_spec.rb +10 -0
  18. data/spec/features/heroku_spec.rb +24 -0
  19. data/spec/features/new_project_spec.rb +68 -0
  20. data/spec/spec_helper.rb +24 -0
  21. data/spec/support/bluebase.rb +49 -0
  22. data/spec/support/fake_github.rb +21 -0
  23. data/spec/support/fake_heroku.rb +32 -0
  24. data/templates/.envrc +1 -0
  25. data/templates/.hound.yml +4 -0
  26. data/templates/.rspec +2 -0
  27. data/templates/.rubocop.yml +20 -0
  28. data/templates/.travis.yml.erb +12 -0
  29. data/templates/Gemfile.erb +74 -0
  30. data/templates/Guardfile +43 -0
  31. data/templates/README.md.erb +30 -0
  32. data/templates/app/_fb_meta_tags.html.slim +6 -0
  33. data/templates/app/_flash.html.slim +2 -0
  34. data/templates/app/_ga_boiler.html.slim +8 -0
  35. data/templates/app/application.css.scss +12 -0
  36. data/templates/app/application.html.slim +23 -0
  37. data/templates/bin/setup +28 -0
  38. data/templates/bluebase_gitignore +18 -0
  39. data/templates/config/application.yml.sample.erb +26 -0
  40. data/templates/config/bluebase_secrets.yml +14 -0
  41. data/templates/config/database.yml.sample.erb +15 -0
  42. data/templates/config/database.yml.travis.erb +4 -0
  43. data/templates/config/devise.rb +298 -0
  44. data/templates/config/en.yml.erb +19 -0
  45. data/templates/config/figaro.rb +2 -0
  46. data/templates/config/i18n-tasks.yml +93 -0
  47. data/templates/config/smtp.rb +9 -0
  48. data/templates/config/staging.rb.erb +9 -0
  49. data/templates/spec/action_mailer.rb +5 -0
  50. data/templates/spec/database_cleaner_and_factory_girl_lint.rb +26 -0
  51. data/templates/spec/factory_girl.rb +3 -0
  52. data/templates/spec/i18n.rb +3 -0
  53. data/templates/spec/rails_helper.rb +30 -0
  54. data/templates/spec/spec_helper.rb +17 -0
  55. metadata +79 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b30695940e980d067e78c365e1bc3725d64d6120
4
- data.tar.gz: 3b0f08169a8752d20ea74c66c361b6e6dd896d23
3
+ metadata.gz: cce8b9840b608aaebdf0183fa3eac8d9fb9af18b
4
+ data.tar.gz: ad92bc123c41e2f23434b81624a9956ec75ef277
5
5
  SHA512:
6
- metadata.gz: 0fdc0e9226fdc656fd8c541d47e0dc6471b5b794246cfc4eea6d5b3eae85aacfc270a7c676f1473bbbfa7afe98dd1814c167f0df5d216af3f204b676a1b1c028
7
- data.tar.gz: a2eb564897732bb1920e8040758a4c9469a2d21e2cc58533a2a347abfc97697b36d855324816f1f599d757cac3324a83a0ed3b6b6292e66f3296ecb560831b6e
6
+ metadata.gz: b53700958a0010816ff6730a20e5dabfd0cd3a98f65691d35ceb970ab06fd5e45fef03e37b58390c98dc5d0b83399a49f954a16c201768024d6af7adff5a7887
7
+ data.tar.gz: d24f48fd12c0bab0142c9365825939a158c009222d83f6cf3674669c5dcc9ed57642d088d742d14745ffcc2998c2fe78905f46cfc11ab35d9c21dfb8929563d3
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ PATH_add bin
data/README.md CHANGED
@@ -2,23 +2,78 @@
2
2
 
3
3
  The base app for Blueprint's Rails apps.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
5
+ ## Features
6
+
7
+ Core gems:
8
+ - [Thin](https://github.com/macournoyer/thin/) for the server
9
+ - [Postgres](https://rubygems.org/gems/pg) to use postgres as the database
10
+ - [Figaro](https://github.com/laserlemon/figaro) for environment variables
11
+
12
+ Component gems:
13
+ - [Devise](https://github.com/plataformatec/devise) for user auth
14
+ - [Simple Form](https://github.com/plataformatec/simple_form) for easier forms
15
+ - [Gon](https://github.com/gazay/gon) to push data to javascript
16
+ - [Kaminari](https://github.com/amatsuda/kaminari) for pagination
17
+ - [Recipient Interceptor](https://github.com/croaky/recipient_interceptor) to stop email sending from staging
18
+
19
+ Frontend gems:
20
+ - [Slim](https://github.com/slim-template/slim-rails) to use the [Slim](http://slim-lang.com/) templating language
21
+ - [Autoprefixer](https://github.com/ai/autoprefixer-rails) to autogenerate vendor prefixes
22
+ - [Flutie](https://github.com/thoughtbot/flutie) for the ```body_class``` view helper
23
+ - [Title](https://github.com/calebthompson/title) for page titles in I18n
24
+
25
+ Development gems:
26
+ - [Annotate](https://github.com/ctran/annotate_models) to annotate models
27
+ - [FFaker](https://github.com/EmmanuelOga/ffaker) to generate random data
28
+ - [Better Errors](https://github.com/charliesome/better_errors) + [Binding of Caller](https://github.com/banister/binding_of_caller) for useful error pages
29
+ - [Quiet Assets](https://github.com/evrone/quiet_assets) to quiet asset rending output in the server
30
+ - [Spring](https://github.com/rails/spring) for fast commands
31
+ - [Rubocop](https://github.com/bbatsov/rubocop) for Rails linting
32
+ - [I18n Tasks](https://github.com/glebm/i18n-tasks) to lint translation files
33
+ - [Awesome Print](https://github.com/michaeldv/awesome_print) for better console object printing
34
+ - [Guard](https://github.com/guard/guard) to run tasks on file changes
35
+ - [Pry](https://github.com/pry/pry) and [Pry Byebug](https://github.com/deivid-rodriguez/pry-byebug) to explore objects and debug
36
+
37
+ Test gems:
38
+ - [RSpec](https://github.com/rspec/rspec-rails) for specs
39
+ - [Capybara](https://github.com/jnicklas/capybara) for integration tests
40
+ - [FactoryGirl](https://github.com/thoughtbot/factory_girl) for test data
41
+ - [Shoulda Matchers](https://github.com/thoughtbot/shoulda) for common RSpec matchers
42
+ - Launchy to use ```save_and_open_page``` in Capybara
43
+ - [Database Cleaner](https://github.com/DatabaseCleaner/database_cleaner) to clear the database for specs
44
+ - [CodeClimate Test Reporter](https://github.com/codeclimate/ruby-test-reporter) to track test coverage
45
+
46
+ Production gems/features (most of these require setup):
47
+ - New Relic for monitoring performance
48
+ - Rollbar for error logging
49
+ - Rails 12Factor for Heroku
50
+
51
+ Other features:
52
+ - Staging environment config
53
+ - Email config using SMTP
54
+ - The ```./bin/setup``` convention for new developer setup
55
+ - Rails' flashes set up and in application layout
56
+ - Configuration for Rubocop/[Hound](https://houndci.com/)
57
+ - A Guardfile set up with [Livereload](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en), RSpec, and Rubocop
58
+ - A few nice time formats set up for localization
59
+ - ```Rack::Deflater``` to compress responses with Gzip
60
+ - A low database connection pool limit
61
+ - ```t()``` and ```l()``` in specs without prefixing with I18n
62
+ - An automatically-created ```SECRET_KEY_BASE``` environment variable in all environments.
63
+ - Configuration for Travis continuous integration.
64
+ - Config for Google Analytics
8
65
 
9
- gem 'bluebase'
10
-
11
- And then execute:
66
+ ## Installation
12
67
 
13
- $ bundle
68
+ Run
14
69
 
15
- Or install it yourself as:
70
+ gem install bluebase
16
71
 
17
- $ gem install bluebase
72
+ Then you can run
18
73
 
19
- ## Usage
74
+ bluebase app_name
20
75
 
21
- TODO: Write usage instructions here
76
+ To create an app called ```app_name```. Optionally append ```-G repo_name``` and ```-H``` to create a Github repo and staging + production Heroku apps, respectively.
22
77
 
23
78
  ## Contributing
24
79
 
@@ -30,7 +85,7 @@ advance for your help!
30
85
  **[Cal Blueprint](http://www.calblueprint.org/)** is a student-run UC Berkeley organization devoted to matching the skills of its members to our desire to see social good enacted in our community. Each semester, teams of 4-5 students work closely with a non-profit to bring technological solutions to the problems they face every day.
31
86
 
32
87
  ## Credits
33
- bluebase was based on thoughtbot's [suspenders](https://github.com/thoughtbot/suspenders)
88
+ Bluebase is a fork of thoughtbot's [suspenders](https://github.com/thoughtbot/suspenders)
34
89
 
35
90
  ## License
36
91
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
2
4
 
5
+ RSpec::Core::RakeTask.new(:rspec)
6
+
7
+ desc 'Run the test suite'
8
+ task default: :rspec
data/bin/bluebase ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'bluebase'
8
+
9
+ templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
10
+ Bluebase::AppGenerator.source_root templates_root
11
+ Bluebase::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
12
+
13
+ Bluebase::AppGenerator.start
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bluebase', 'bundler')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bluebase', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bluebase', 'rspec')
data/bluebase.gemspec CHANGED
@@ -26,5 +26,6 @@ Bluebase is Blueprint's base Rails app. We use it internally to get a jump start
26
26
  spec.add_runtime_dependency "bundler", "~> 1.6"
27
27
 
28
28
  spec.add_development_dependency "rspec", "~> 3.1", ">= 3.1.0"
29
+ spec.add_development_dependency "pry", "~> 0.10"
29
30
  spec.add_development_dependency "capybara", "~> 2.4", ">= 2.4.4"
30
31
  end
data/lib/bluebase.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require "bluebase/version"
2
-
3
- module Bluebase
4
- def self.hello
5
- 'world'
6
- end
7
- end
2
+ require "bluebase/generators/app_generator"
3
+ require "bluebase/actions"
4
+ require "bluebase/app_builder"
@@ -0,0 +1,25 @@
1
+ module Bluebase
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ raise "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, "w") { |file| file.write(contents) }
10
+ end
11
+
12
+ def action_mailer_host(rails_env, host)
13
+ host_config = "config.action_mailer.default_url_options = { host: '#{host}' }"
14
+ configure_environment(rails_env, host_config)
15
+ end
16
+
17
+ def configure_environment(rails_env, config)
18
+ inject_into_file(
19
+ "config/environments/#{rails_env}.rb",
20
+ "\n\n #{config}",
21
+ before: "\nend"
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,356 @@
1
+ module Bluebase
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Bluebase::Actions
4
+
5
+ #########################################################
6
+ # Root directory files
7
+ #########################################################
8
+ def readme
9
+ template "README.md.erb", "README.md"
10
+ end
11
+
12
+ def replace_gemfile
13
+ remove_file "Gemfile"
14
+ template "Gemfile.erb", "Gemfile"
15
+ end
16
+
17
+ def add_envrc
18
+ copy_file ".envrc", ".envrc"
19
+ end
20
+
21
+ def replace_gitignore
22
+ remove_file ".gitignore"
23
+ copy_file "bluebase_gitignore", ".gitignore"
24
+ end
25
+
26
+ def add_rubocop_and_hound_config
27
+ copy_file ".hound.yml", ".hound.yml"
28
+ copy_file ".rubocop.yml", ".rubocop.yml"
29
+ end
30
+
31
+ def add_rvm_config
32
+ create_file ".ruby-gemset", "#{app_path}\n"
33
+ create_file ".ruby-version", "#{Bluebase::RUBY_VERSION}\n"
34
+ end
35
+
36
+ def add_travis_config
37
+ template ".travis.yml.erb", ".travis.yml"
38
+ end
39
+
40
+ def add_guardfile
41
+ copy_file "Guardfile", "Guardfile"
42
+ end
43
+
44
+ def add_dot_rspec
45
+ copy_file ".rspec", ".rspec"
46
+ end
47
+
48
+ #########################################################
49
+ # app/ directory files
50
+ #########################################################
51
+ def add_vendor_dirs
52
+ %w(app/assets/javascripts/vendor app/assets/stylesheets/vendor).each do |dir|
53
+ run "mkdir #{dir}"
54
+ run "touch #{dir}/.keep"
55
+ end
56
+ end
57
+
58
+ def replace_application_css_with_scss
59
+ base_dir = "app/assets/stylesheets"
60
+ remove_file "#{base_dir}/application.css"
61
+ copy_file "app/application.css.scss", "#{base_dir}/application.css.scss"
62
+ end
63
+
64
+ def add_application_folder_and_files_to_views
65
+ base_dir = "app/views/application"
66
+ empty_directory base_dir
67
+ copy_file "app/_flash.html.slim", "#{base_dir}/_flash.html.slim"
68
+ copy_file "app/_ga_boiler.html.slim", "#{base_dir}/_ga_boiler.html.slim"
69
+ copy_file "app/_fb_meta_tags.html.slim", "#{base_dir}/_fb_meta_tags.html.slim"
70
+ end
71
+
72
+ def replace_application_erb_with_slim
73
+ base_dir = "app/views/layouts"
74
+ remove_file "#{base_dir}/application.html.erb"
75
+ copy_file "app/application.html.slim", "#{base_dir}/application.html.slim"
76
+ end
77
+
78
+ #########################################################
79
+ # bin/ directory files
80
+ #########################################################
81
+ def add_setup_to_bin
82
+ copy_file "bin/setup", "bin/setup"
83
+ run "chmod a+x bin/setup"
84
+ end
85
+
86
+ #########################################################
87
+ # config/ directory files
88
+ #########################################################
89
+ def configure_application_environment
90
+ config = <<-RUBY
91
+
92
+ config.generators do |generate|
93
+ generate.helper false
94
+ generate.javascript_engine false
95
+ generate.request_specs false
96
+ generate.routing_specs false
97
+ generate.stylesheets false
98
+ generate.test_framework :rspec
99
+ generate.view_specs false
100
+ end
101
+
102
+ RUBY
103
+ inject_into_class "config/application.rb", "Application", config
104
+
105
+ config = <<-RUBY
106
+ config.active_record.default_timezone = :utc
107
+ RUBY
108
+ inject_into_class "config/application.rb", "Application", config
109
+
110
+ config = <<-RUBY
111
+ config.i18n.enforce_available_locales = true
112
+ RUBY
113
+ inject_into_class "config/application.rb", "Application", config
114
+
115
+ config = <<-RUBY
116
+ config.action_controller.action_on_unpermitted_parameters = :raise
117
+ RUBY
118
+
119
+ inject_into_class "config/application.rb", "Application", config
120
+ end
121
+
122
+ def configure_development_environment
123
+ replace_in_file "config/environments/development.rb",
124
+ "raise_delivery_errors = false", "raise_delivery_errors = true"
125
+ inject_into_file "config/environments/development.rb",
126
+ " # Don't send emails in development\n config.action_mailer.perform_deliveries = false",
127
+ after: "raise_delivery_errors = true\n"
128
+ raise_on_missing_translations_in "development"
129
+ action_mailer_host "development", "localhost:3000"
130
+ end
131
+
132
+ def configure_test_environment
133
+ raise_on_missing_translations_in "test"
134
+ end
135
+
136
+ def configure_production_environment
137
+ prepend_file "config/environments/production.rb",
138
+ %{require Rails.root.join("config/smtp")\n}
139
+
140
+ config = <<-RUBY
141
+
142
+ config.action_mailer.delivery_method = :smtp
143
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
144
+ RUBY
145
+ inject_into_file "config/environments/production.rb", config,
146
+ after: "config.action_mailer.raise_delivery_errors = false"
147
+
148
+ config = <<-RUBY
149
+
150
+ # Enable deflate / gzip compression of controller-generated responses
151
+ config.middleware.use Rack::Deflater
152
+ RUBY
153
+ inject_into_file "config/environments/production.rb", config,
154
+ after: "config.serve_static_assets = false\n"
155
+
156
+ action_mailer_host "production", "please-change-me.com"
157
+ end
158
+
159
+ def add_staging_environment
160
+ template "config/staging.rb.erb", "config/environments/staging.rb"
161
+ end
162
+
163
+ def add_devise_config
164
+ copy_file "config/devise.rb", "config/initializers/devise.rb"
165
+ end
166
+
167
+ def add_figaro_config
168
+ copy_file "config/figaro.rb", "config/initializers/figaro.rb"
169
+ end
170
+
171
+ def replace_en_yml
172
+ file = "config/locales/en.yml"
173
+ remove_file file
174
+ template "config/en.yml.erb", file
175
+ end
176
+
177
+ def add_application_yml
178
+ template "config/application.yml.sample.erb", "config/application.yml.sample"
179
+
180
+ template "config/application.yml.sample.erb", "config/application.yml"
181
+ replace_in_file "config/application.yml",
182
+ "# Copy this file into application.yml and change env variables as necessary.",
183
+ "# Change env variables as necessary."
184
+
185
+ template "config/application.yml.sample.erb", "config/application.yml.travis"
186
+ replace_in_file "config/application.yml.travis",
187
+ "# Copy this file into application.yml and change env variables as necessary.",
188
+ "# Change env variables as necessary for Travis."
189
+ end
190
+
191
+ def add_database_yml
192
+ template "config/database.yml.sample.erb", "config/database.yml.sample"
193
+
194
+ remove_file "config/database.yml"
195
+ template "config/database.yml.sample.erb", "config/database.yml"
196
+ replace_in_file "config/database.yml",
197
+ "# and then copy the file into database.yml", ""
198
+ end
199
+
200
+ def add_travis_database_yml
201
+ template "config/database.yml.travis.erb", "config/database.yml.travis"
202
+ end
203
+
204
+ def add_i18n_tasks_yml
205
+ file = "config/i18n-tasks.yml"
206
+ copy_file file, file
207
+ end
208
+
209
+ def replace_secrets_yml
210
+ file = "config/secrets.yml"
211
+ remove_file file
212
+ copy_file "config/bluebase_secrets.yml", file
213
+ end
214
+
215
+ def add_smtp_settings
216
+ file = "config/smtp.rb"
217
+ copy_file file, file
218
+ end
219
+
220
+ def remove_routes_comment_lines
221
+ replace_in_file "config/routes.rb",
222
+ /Rails\.application\.routes\.draw do.*end/m,
223
+ "Rails.application.routes.draw do\nend"
224
+ end
225
+
226
+ #########################################################
227
+ # spec/ directory files
228
+ #########################################################
229
+ def add_spec_dirs
230
+ empty_directory "spec"
231
+ empty_directory_with_keep_file "spec/features"
232
+ empty_directory_with_keep_file "spec/factories"
233
+ end
234
+
235
+ def configure_rspec
236
+ %w(spec/rails_helper.rb spec/spec_helper.rb).each do |file|
237
+ copy_file file, file
238
+ end
239
+ end
240
+
241
+ def configure_factorygirl
242
+ copy_file "spec/factory_girl.rb", "spec/support/factory_girl.rb"
243
+ end
244
+
245
+ def configure_actionmailer
246
+ copy_file "spec/action_mailer.rb", "spec/support/action_mailer.rb"
247
+ end
248
+
249
+ def configure_i18n
250
+ copy_file "spec/i18n.rb", "spec/support/i18n.rb"
251
+ end
252
+
253
+ def configure_database_cleaner
254
+ copy_file "spec/database_cleaner_and_factory_girl_lint.rb",
255
+ "spec/support/database_cleaner_and_factory_girl_lint.rb"
256
+ end
257
+
258
+ #########################################################
259
+ # git/heroku setup
260
+ #########################################################
261
+ def git_init
262
+ run 'git init'
263
+ end
264
+
265
+ def create_github_repo(repo_name)
266
+ path_addition = override_path_for_tests
267
+ run "#{path_addition} hub create #{repo_name}"
268
+ end
269
+
270
+ def create_heroku_apps
271
+ run_heroku "create #{heroku_app_name :production}", "production"
272
+ run_heroku "create #{heroku_app_name :staging}", "staging"
273
+ run_heroku "config:add RACK_ENV=staging RAILS_ENV=staging", "staging"
274
+ end
275
+
276
+ def set_heroku_remotes
277
+ remotes = <<-SHELL
278
+
279
+ # Set up the staging and production apps.
280
+ #{join_heroku_app :staging}
281
+ #{join_heroku_app :production}
282
+ SHELL
283
+
284
+ append_file "bin/setup", remotes
285
+ end
286
+
287
+ def set_heroku_env_variables
288
+ config = <<-SHELL
289
+ # Sets Heroku env variables
290
+ figaro heroku:set -a #{heroku_app_name :production} -e production
291
+ figaro heroku:set -a #{heroku_app_name :staging} -e production
292
+ SHELL
293
+ append_file "bin/setup", config
294
+ end
295
+
296
+ def add_heroku_addons
297
+ config = <<-SHELL
298
+
299
+ # Heroku addons for production
300
+ heroku addons:add mandrill --app #{heroku_app_name :production}
301
+ heroku addons:add newrelic:stark --app #{heroku_app_name :production}
302
+ heroku addons:add rollbar --app #{heroku_app_name :production}
303
+ SHELL
304
+ append_file "bin/setup", config
305
+ end
306
+
307
+ def set_memory_management_variable
308
+ %w(staging production).each do |environment|
309
+ run_heroku "config:add NEW_RELIC_AGGRESSIVE_KEEPALIVE=1", environment
310
+ end
311
+ end
312
+
313
+ #########################################################
314
+ # Helper methods
315
+ #########################################################
316
+ private
317
+
318
+ def raise_on_missing_translations_in(environment)
319
+ config = "config.action_view.raise_on_missing_translations = true"
320
+
321
+ uncomment_lines("config/environments/#{environment}.rb", config)
322
+ end
323
+
324
+ def run_heroku(command, environment)
325
+ path_addition = override_path_for_tests
326
+ run "#{path_addition} heroku #{command} --remote #{environment}"
327
+ end
328
+
329
+ def heroku_app_name(environment)
330
+ "#{app_name.gsub '_', '-'}-#{environment}"
331
+ end
332
+
333
+ def join_heroku_app(environment)
334
+ name = heroku_app_name environment
335
+ <<-SHELL
336
+ if heroku join --app #{name} &> /dev/null; then
337
+ git remote add #{environment} git@heroku.com:#{name}.git || true
338
+ printf 'You are a collaborator on the "#{name}" Heroku app\n'
339
+ else
340
+ printf 'Ask for access to the "#{name}" Heroku app\n'
341
+ fi
342
+ SHELL
343
+ end
344
+
345
+ def generate_secret
346
+ SecureRandom.hex(64)
347
+ end
348
+
349
+ def override_path_for_tests
350
+ if ENV['TESTING']
351
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
352
+ "PATH=#{support_bin}:$PATH"
353
+ end
354
+ end
355
+ end
356
+ end