bluebase_api 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.envrc +1 -0
- data/.gitignore +22 -0
- data/.hound.yml +6 -0
- data/.rubocop.yml +12 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +8 -0
- data/bin/bluebase_api +13 -0
- data/bin/build +6 -0
- data/bin/bundler +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bluebase_api.gemspec +31 -0
- data/lib/bluebase_api.rb +4 -0
- data/lib/bluebase_api/actions.rb +25 -0
- data/lib/bluebase_api/app_builder.rb +379 -0
- data/lib/bluebase_api/generators/app_generator.rb +151 -0
- data/lib/bluebase_api/version.rb +5 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/github_spec.rb +10 -0
- data/spec/features/heroku_spec.rb +24 -0
- data/spec/features/new_project_spec.rb +68 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/bluebase_api.rb +49 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +32 -0
- data/templates/.envrc +1 -0
- data/templates/.hound.yml +12 -0
- data/templates/.rspec +2 -0
- data/templates/.rubocop.yml +20 -0
- data/templates/Gemfile.erb +65 -0
- data/templates/Guardfile +43 -0
- data/templates/README.md.erb +30 -0
- data/templates/app/controllers/api/base_controller.rb +3 -0
- data/templates/app/controllers/bluebase_api_application_controller.rb +5 -0
- data/templates/bin/setup +27 -0
- data/templates/bluebase_api_gitignore +18 -0
- data/templates/config/application.yml.sample.erb +27 -0
- data/templates/config/bluebase_api_routes.rb +7 -0
- data/templates/config/bluebase_api_secrets.yml +14 -0
- data/templates/config/database.yml.sample.erb +15 -0
- data/templates/config/database.yml.travis.erb +4 -0
- data/templates/config/devise.rb +298 -0
- data/templates/config/en.yml.erb +19 -0
- data/templates/config/figaro.rb +2 -0
- data/templates/config/i18n-tasks.yml +93 -0
- data/templates/config/smtp.rb +9 -0
- data/templates/config/staging.rb.erb +9 -0
- data/templates/spec/action_mailer.rb +5 -0
- data/templates/spec/database_cleaner_and_factory_girl_lint.rb +26 -0
- data/templates/spec/factory_girl.rb +3 -0
- data/templates/spec/i18n.rb +3 -0
- data/templates/spec/rails_helper.rb +32 -0
- data/templates/spec/spec_helper.rb +17 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6ddcaa4125f7f7b4ae65c32b1b4c12c243b4809
|
4
|
+
data.tar.gz: 238f701b724851a0af98c568cc9b046fb4e55909
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93ed4092807a3c739e96d36394bd15fc38d613db67b97b73ec71f92614cdd7ba8595b4a6a58296b3a488f379f69ea8d14ee97b6e0288deb3fe9749c123221a4f
|
7
|
+
data.tar.gz: 00259e82b18122fe23bd387c66183a3cea3f61556999215fea1ee5dd1d6473424d9d8c690692216dfdbbf6c8f9500554c6e264338df84c585be81b0f004310b1
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PATH_add bin
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bluebase_api
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Cal Blueprint
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Bluebase
|
2
|
+
|
3
|
+
The base API for Blueprint's Rails mobile applications.
|
4
|
+
|
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
|
+
- [Gon](https://github.com/gazay/gon) to push data to javascript
|
15
|
+
- [Kaminari](https://github.com/amatsuda/kaminari) for pagination
|
16
|
+
- [Recipient Interceptor](https://github.com/croaky/recipient_interceptor) to stop email sending from staging
|
17
|
+
|
18
|
+
Development gems:
|
19
|
+
- [Annotate](https://github.com/ctran/annotate_models) to annotate models
|
20
|
+
- [FFaker](https://github.com/EmmanuelOga/ffaker) to generate random data
|
21
|
+
- [Better Errors](https://github.com/charliesome/better_errors) + [Binding of Caller](https://github.com/banister/binding_of_caller) for useful error pages
|
22
|
+
- [Quiet Assets](https://github.com/evrone/quiet_assets) to quiet asset rending output in the server
|
23
|
+
- [Spring](https://github.com/rails/spring) for fast commands
|
24
|
+
- [Rubocop](https://github.com/bbatsov/rubocop) for Rails linting
|
25
|
+
- [I18n Tasks](https://github.com/glebm/i18n-tasks) to lint translation files
|
26
|
+
- [Awesome Print](https://github.com/michaeldv/awesome_print) for better console object printing
|
27
|
+
- [Guard](https://github.com/guard/guard) to run tasks on file changes
|
28
|
+
- [Pry](https://github.com/pry/pry) and [Pry Byebug](https://github.com/deivid-rodriguez/pry-byebug) to explore objects and debug
|
29
|
+
|
30
|
+
Test gems:
|
31
|
+
- [RSpec](https://github.com/rspec/rspec-rails) for specs
|
32
|
+
- [Capybara](https://github.com/jnicklas/capybara) for integration tests
|
33
|
+
- [FactoryGirl](https://github.com/thoughtbot/factory_girl) for test data
|
34
|
+
- [Shoulda Matchers](https://github.com/thoughtbot/shoulda) for common RSpec matchers
|
35
|
+
- Launchy to use ```save_and_open_page``` in Capybara
|
36
|
+
- [Database Cleaner](https://github.com/DatabaseCleaner/database_cleaner) to clear the database for specs
|
37
|
+
- [CodeClimate Test Reporter](https://github.com/codeclimate/ruby-test-reporter) to track test coverage
|
38
|
+
|
39
|
+
Production gems/features (most of these require setup):
|
40
|
+
- New Relic for monitoring performance
|
41
|
+
- Rollbar for error logging
|
42
|
+
- Rails 12Factor for Heroku
|
43
|
+
|
44
|
+
Other features:
|
45
|
+
- Staging environment config
|
46
|
+
- Email config using SMTP
|
47
|
+
- The ```./bin/setup``` convention for new developer setup
|
48
|
+
- Rails' flashes set up and in application layout
|
49
|
+
- Configuration for Rubocop/[Hound](https://houndci.com/)
|
50
|
+
- A Guardfile set up with [Livereload](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en), RSpec, and Rubocop
|
51
|
+
- A few nice time formats set up for localization
|
52
|
+
- ```Rack::Deflater``` to compress responses with Gzip
|
53
|
+
- A low database connection pool limit
|
54
|
+
- ```t()``` and ```l()``` in specs without prefixing with I18n
|
55
|
+
- An automatically-created ```SECRET_KEY_BASE``` environment variable in all environments.
|
56
|
+
- Config for Google Analytics
|
57
|
+
|
58
|
+
## Installation
|
59
|
+
|
60
|
+
Run
|
61
|
+
|
62
|
+
gem install bluebase_api
|
63
|
+
|
64
|
+
Then you can run
|
65
|
+
|
66
|
+
bluebase_api app_name
|
67
|
+
|
68
|
+
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.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Feel free to open issues or send pull requests with improvements. Thanks in
|
73
|
+
advance for your help!
|
74
|
+
|
75
|
+
## Cal Blueprint
|
76
|
+
![bp](http://bptech.berkeley.edu/assets/logo-full-large-d6419503b443e360bc6c404a16417583.png "BP Banner")
|
77
|
+
**[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.
|
78
|
+
|
79
|
+
## Credits
|
80
|
+
Bluebase is a fork of thoughtbot's [suspenders](https://github.com/thoughtbot/suspenders)
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
Bluebase is Copyright © 2014 Cal Blueprint. It is free software, and may be redistributed under the terms
|
85
|
+
specified in the LICENSE.txt file.
|
data/Rakefile
ADDED
data/bin/bluebase_api
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_api'
|
8
|
+
|
9
|
+
templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
|
10
|
+
Bluebase_api::AppGenerator.source_root templates_root
|
11
|
+
Bluebase_api::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
|
12
|
+
|
13
|
+
Bluebase_api::AppGenerator.start
|
data/bin/build
ADDED
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_api', '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_api', '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_api', 'rspec')
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bluebase_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bluebase_api"
|
8
|
+
spec.version = Bluebase_api::VERSION
|
9
|
+
spec.authors = ["Sam Lau, Tricia Fu and Quinton Dang", "Cal Blueprint"]
|
10
|
+
spec.email = ["team@calblueprint.org"]
|
11
|
+
spec.summary = "Bluebase_api creates a Rails API app with all of our favorite defaults."
|
12
|
+
spec.description = <<-HERE
|
13
|
+
Bluebase_api is Blueprint's base Rails API app. We use it internally to get a jump start on our Rails projects.
|
14
|
+
HERE
|
15
|
+
spec.homepage = "https://github.com/calblueprint/bluebase_api"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.required_ruby_version = ">= #{Bluebase_api::RUBY_VERSION}"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "rails", Bluebase_api::RAILS_VERSION
|
26
|
+
spec.add_runtime_dependency "bundler", "~> 1.6"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.2", ">= 3.2.0"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
30
|
+
spec.add_development_dependency "capybara", "~> 2.4"
|
31
|
+
end
|
data/lib/bluebase_api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bluebase_api
|
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,379 @@
|
|
1
|
+
module Bluebase_api
|
2
|
+
class AppBuilder < Rails::AppBuilder
|
3
|
+
include Bluebase_api::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_api_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_api::RUBY_VERSION}\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_guardfile
|
37
|
+
copy_file "Guardfile", "Guardfile"
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_dot_rspec
|
41
|
+
copy_file ".rspec", ".rspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
#########################################################
|
45
|
+
# app/ directory files
|
46
|
+
#########################################################
|
47
|
+
|
48
|
+
# Only front-end changes were contained here, so removed for API app.
|
49
|
+
def configure_api_directory
|
50
|
+
empty_directory "app/controllers/api"
|
51
|
+
end
|
52
|
+
|
53
|
+
def configure_v1_directory
|
54
|
+
empty_directory_with_keep_file "app/controllers/api/v1"
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_base_controller
|
58
|
+
template "app/controllers/api/base_controller.rb", "app/controllers/api/base_controller.rb"
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace_application_controller
|
62
|
+
file = "app/controllers/application_controller.rb"
|
63
|
+
remove_file file
|
64
|
+
template "app/controllers/bluebase_api_application_controller.rb", file
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_serializers_directory
|
68
|
+
empty_directory_with_keep_file "app/serializers"
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove_app_assets_directory
|
72
|
+
run "rm -rf app/assets"
|
73
|
+
end
|
74
|
+
|
75
|
+
def remove_app_views_directory
|
76
|
+
run "rm -rf app/views"
|
77
|
+
end
|
78
|
+
|
79
|
+
#########################################################
|
80
|
+
# vendor directory files
|
81
|
+
#########################################################
|
82
|
+
def remove_vendor_assets_directories
|
83
|
+
run "rm -rf vendor"
|
84
|
+
empty_directory_with_keep_file "vendor"
|
85
|
+
end
|
86
|
+
#########################################################
|
87
|
+
# public/ directory files
|
88
|
+
#########################################################
|
89
|
+
def remove_html_files
|
90
|
+
remove_file "public/404.html"
|
91
|
+
remove_file "public/422.html"
|
92
|
+
remove_file "public/500.html"
|
93
|
+
run "rm -rf public/favicon.ico"
|
94
|
+
end
|
95
|
+
|
96
|
+
#########################################################
|
97
|
+
# bin/ directory files
|
98
|
+
#########################################################
|
99
|
+
def add_setup_to_bin
|
100
|
+
copy_file "bin/setup", "bin/setup"
|
101
|
+
run "chmod a+x bin/setup"
|
102
|
+
end
|
103
|
+
|
104
|
+
#########################################################
|
105
|
+
# lib/ directory files
|
106
|
+
#########################################################
|
107
|
+
def remove_lib_assets_directory
|
108
|
+
run "rm -rf lib/assets"
|
109
|
+
end
|
110
|
+
|
111
|
+
#########################################################
|
112
|
+
# tmp/ directory files
|
113
|
+
#########################################################
|
114
|
+
def remove_tmp_assets_directory
|
115
|
+
run "rm -rf tmp/cache"
|
116
|
+
empty_directory_with_keep_file "tmp/cache"
|
117
|
+
end
|
118
|
+
#########################################################
|
119
|
+
# config/ directory files
|
120
|
+
#########################################################
|
121
|
+
def configure_application_environment
|
122
|
+
config = <<-RUBY
|
123
|
+
|
124
|
+
config.generators do |generate|
|
125
|
+
generate.helper false
|
126
|
+
generate.javascript_engine false
|
127
|
+
generate.request_specs false
|
128
|
+
generate.routing_specs false
|
129
|
+
generate.stylesheets false
|
130
|
+
generate.test_framework :rspec
|
131
|
+
generate.view_specs false
|
132
|
+
end
|
133
|
+
|
134
|
+
RUBY
|
135
|
+
inject_into_class "config/application.rb", "Application", config
|
136
|
+
|
137
|
+
config = <<-RUBY
|
138
|
+
config.active_record.default_timezone = :utc
|
139
|
+
RUBY
|
140
|
+
inject_into_class "config/application.rb", "Application", config
|
141
|
+
|
142
|
+
config = <<-RUBY
|
143
|
+
config.i18n.enforce_available_locales = true
|
144
|
+
RUBY
|
145
|
+
inject_into_class "config/application.rb", "Application", config
|
146
|
+
|
147
|
+
config = <<-RUBY
|
148
|
+
config.action_controller.action_on_unpermitted_parameters = :raise
|
149
|
+
RUBY
|
150
|
+
|
151
|
+
inject_into_class "config/application.rb", "Application", config
|
152
|
+
end
|
153
|
+
|
154
|
+
def configure_development_environment
|
155
|
+
replace_in_file "config/environments/development.rb",
|
156
|
+
"raise_delivery_errors = false", "raise_delivery_errors = true"
|
157
|
+
inject_into_file "config/environments/development.rb",
|
158
|
+
" # Don't send emails in development\n config.action_mailer.perform_deliveries = false",
|
159
|
+
after: "raise_delivery_errors = true\n"
|
160
|
+
raise_on_missing_translations_in "development"
|
161
|
+
action_mailer_host "development", "localhost:3000"
|
162
|
+
end
|
163
|
+
|
164
|
+
def configure_test_environment
|
165
|
+
raise_on_missing_translations_in "test"
|
166
|
+
end
|
167
|
+
|
168
|
+
def configure_production_environment
|
169
|
+
prepend_file "config/environments/production.rb",
|
170
|
+
%{require Rails.root.join("config/smtp")\n}
|
171
|
+
|
172
|
+
config = <<-RUBY
|
173
|
+
|
174
|
+
config.action_mailer.delivery_method = :smtp
|
175
|
+
config.action_mailer.smtp_settings = SMTP_SETTINGS
|
176
|
+
RUBY
|
177
|
+
inject_into_file "config/environments/production.rb", config,
|
178
|
+
after: "config.action_mailer.raise_delivery_errors = false"
|
179
|
+
|
180
|
+
config = <<-RUBY
|
181
|
+
|
182
|
+
# Enable deflate / gzip compression of controller-generated responses
|
183
|
+
config.middleware.use Rack::Deflater
|
184
|
+
RUBY
|
185
|
+
inject_into_file "config/environments/production.rb", config,
|
186
|
+
after: "config.serve_static_assets = false\n"
|
187
|
+
|
188
|
+
action_mailer_host "production", "please-change-me.com"
|
189
|
+
end
|
190
|
+
|
191
|
+
def add_staging_environment
|
192
|
+
template "config/staging.rb.erb", "config/environments/staging.rb"
|
193
|
+
end
|
194
|
+
|
195
|
+
def add_devise_config
|
196
|
+
copy_file "config/devise.rb", "config/initializers/devise.rb"
|
197
|
+
end
|
198
|
+
|
199
|
+
def add_figaro_config
|
200
|
+
copy_file "config/figaro.rb", "config/initializers/figaro.rb"
|
201
|
+
end
|
202
|
+
|
203
|
+
def replace_en_yml
|
204
|
+
file = "config/locales/en.yml"
|
205
|
+
remove_file file
|
206
|
+
template "config/en.yml.erb", file
|
207
|
+
end
|
208
|
+
|
209
|
+
def add_application_yml
|
210
|
+
template "config/application.yml.sample.erb", "config/application.yml.sample"
|
211
|
+
|
212
|
+
template "config/application.yml.sample.erb", "config/application.yml"
|
213
|
+
replace_in_file "config/application.yml",
|
214
|
+
"# Copy this file into application.yml and change env variables as necessary.",
|
215
|
+
"# Change env variables as necessary."
|
216
|
+
end
|
217
|
+
|
218
|
+
def add_database_yml
|
219
|
+
template "config/database.yml.sample.erb", "config/database.yml.sample"
|
220
|
+
|
221
|
+
remove_file "config/database.yml"
|
222
|
+
template "config/database.yml.sample.erb", "config/database.yml"
|
223
|
+
replace_in_file "config/database.yml",
|
224
|
+
"# and then copy the file into database.yml", ""
|
225
|
+
end
|
226
|
+
|
227
|
+
def add_i18n_tasks_yml
|
228
|
+
file = "config/i18n-tasks.yml"
|
229
|
+
copy_file file, file
|
230
|
+
end
|
231
|
+
|
232
|
+
def replace_secrets_yml
|
233
|
+
file = "config/secrets.yml"
|
234
|
+
remove_file file
|
235
|
+
copy_file "config/bluebase_api_secrets.yml", file
|
236
|
+
end
|
237
|
+
|
238
|
+
def add_smtp_settings
|
239
|
+
file = "config/smtp.rb"
|
240
|
+
copy_file file, file
|
241
|
+
end
|
242
|
+
|
243
|
+
def replace_routes_rb
|
244
|
+
file = "config/routes.rb"
|
245
|
+
remove_file file
|
246
|
+
template "config/bluebase_api_routes.rb", file
|
247
|
+
end
|
248
|
+
|
249
|
+
#########################################################
|
250
|
+
# spec/ directory files
|
251
|
+
#########################################################
|
252
|
+
def add_spec_dirs
|
253
|
+
empty_directory "spec"
|
254
|
+
empty_directory_with_keep_file "spec/features"
|
255
|
+
empty_directory_with_keep_file "spec/factories"
|
256
|
+
end
|
257
|
+
|
258
|
+
def configure_rspec
|
259
|
+
%w(spec/rails_helper.rb spec/spec_helper.rb).each do |file|
|
260
|
+
copy_file file, file
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def configure_factorygirl
|
265
|
+
copy_file "spec/factory_girl.rb", "spec/support/factory_girl.rb"
|
266
|
+
end
|
267
|
+
|
268
|
+
def configure_actionmailer
|
269
|
+
copy_file "spec/action_mailer.rb", "spec/support/action_mailer.rb"
|
270
|
+
end
|
271
|
+
|
272
|
+
def configure_i18n
|
273
|
+
copy_file "spec/i18n.rb", "spec/support/i18n.rb"
|
274
|
+
end
|
275
|
+
|
276
|
+
def configure_database_cleaner
|
277
|
+
copy_file "spec/database_cleaner_and_factory_girl_lint.rb",
|
278
|
+
"spec/support/database_cleaner_and_factory_girl_lint.rb"
|
279
|
+
end
|
280
|
+
|
281
|
+
#########################################################
|
282
|
+
# git/heroku setup
|
283
|
+
#########################################################
|
284
|
+
def git_init
|
285
|
+
run 'git init'
|
286
|
+
end
|
287
|
+
|
288
|
+
def create_github_repo(repo_name)
|
289
|
+
path_addition = override_path_for_tests
|
290
|
+
run "#{path_addition} hub create #{repo_name}"
|
291
|
+
end
|
292
|
+
|
293
|
+
def create_heroku_apps
|
294
|
+
run_heroku "create #{heroku_app_name :production}", "production"
|
295
|
+
run_heroku "create #{heroku_app_name :staging}", "staging"
|
296
|
+
run_heroku "config:add RACK_ENV=staging RAILS_ENV=staging", "staging"
|
297
|
+
end
|
298
|
+
|
299
|
+
def set_heroku_remotes
|
300
|
+
remotes = <<-SHELL
|
301
|
+
|
302
|
+
# Set up the staging and production apps.
|
303
|
+
#{join_heroku_app :staging}
|
304
|
+
#{join_heroku_app :production}
|
305
|
+
SHELL
|
306
|
+
|
307
|
+
append_file "bin/setup", remotes
|
308
|
+
end
|
309
|
+
|
310
|
+
def set_heroku_env_variables
|
311
|
+
config = <<-SHELL
|
312
|
+
# Sets Heroku env variables
|
313
|
+
figaro heroku:set -a #{heroku_app_name :production} -e production
|
314
|
+
figaro heroku:set -a #{heroku_app_name :staging} -e production
|
315
|
+
SHELL
|
316
|
+
append_file "bin/setup", config
|
317
|
+
end
|
318
|
+
|
319
|
+
def add_heroku_addons
|
320
|
+
config = <<-SHELL
|
321
|
+
|
322
|
+
# Heroku addons for production
|
323
|
+
heroku addons:add mandrill --app #{heroku_app_name :production}
|
324
|
+
heroku addons:add newrelic:stark --app #{heroku_app_name :production}
|
325
|
+
heroku addons:add rollbar --app #{heroku_app_name :production}
|
326
|
+
SHELL
|
327
|
+
append_file "bin/setup", config
|
328
|
+
end
|
329
|
+
|
330
|
+
def set_memory_management_variable
|
331
|
+
%w(staging production).each do |environment|
|
332
|
+
run_heroku "config:add NEW_RELIC_AGGRESSIVE_KEEPALIVE=1", environment
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
#########################################################
|
337
|
+
# Helper methods
|
338
|
+
#########################################################
|
339
|
+
private
|
340
|
+
|
341
|
+
def raise_on_missing_translations_in(environment)
|
342
|
+
config = "config.action_view.raise_on_missing_translations = true"
|
343
|
+
|
344
|
+
uncomment_lines("config/environments/#{environment}.rb", config)
|
345
|
+
end
|
346
|
+
|
347
|
+
def run_heroku(command, environment)
|
348
|
+
path_addition = override_path_for_tests
|
349
|
+
run "#{path_addition} heroku #{command} --remote #{environment}"
|
350
|
+
end
|
351
|
+
|
352
|
+
def heroku_app_name(environment)
|
353
|
+
"#{app_name.gsub '_', '-'}-#{environment}"
|
354
|
+
end
|
355
|
+
|
356
|
+
def join_heroku_app(environment)
|
357
|
+
name = heroku_app_name environment
|
358
|
+
<<-SHELL
|
359
|
+
if heroku join --app #{name} &> /dev/null; then
|
360
|
+
git remote add #{environment} git@heroku.com:#{name}.git || true
|
361
|
+
printf 'You are a collaborator on the "#{name}" Heroku app\n'
|
362
|
+
else
|
363
|
+
printf 'Ask for access to the "#{name}" Heroku app\n'
|
364
|
+
fi
|
365
|
+
SHELL
|
366
|
+
end
|
367
|
+
|
368
|
+
def generate_secret
|
369
|
+
SecureRandom.hex(64)
|
370
|
+
end
|
371
|
+
|
372
|
+
def override_path_for_tests
|
373
|
+
if ENV['TESTING']
|
374
|
+
support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
|
375
|
+
"PATH=#{support_bin}:$PATH"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|