Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
show all
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary
collapse
Methods included from Actions
#action_mailer_asset_host, #action_mailer_host, #configure_environment, #expand_json, #gem, #replace_in_file
Instance Method Details
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/suspenders/app_builder.rb', line 175
def configure_action_mailer
action_mailer_host "development", %("localhost:3000")
action_mailer_asset_host "development", %("http://localhost:3000")
action_mailer_host "test", %("www.example.com")
action_mailer_asset_host "test", %("http://www.example.com")
action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")}
action_mailer_asset_host(
"production",
%q{"https://#{ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))}"}
)
end
|
166
167
168
|
# File 'lib/suspenders/app_builder.rb', line 166
def configure_action_mailer_in_specs
copy_file "action_mailer.rb", "spec/support/action_mailer.rb"
end
|
194
195
196
197
|
# File 'lib/suspenders/app_builder.rb', line 194
def configure_automatic_deployment
append_file "Procfile", "release: bin/auto_migrate\n"
copy_file "bin_auto_migrate", "bin/auto_migrate"
end
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/suspenders/app_builder.rb', line 83
def configure_generators
config = <<-RUBY
config.generators do |generate|
generate.helper false
generate.javascripts false
generate.controller_specs false
generate.request_specs true
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
|
161
162
163
164
|
# File 'lib/suspenders/app_builder.rb', line 161
def configure_i18n_for_missing_translations
raise_on_missing_translations_in("development")
raise_on_missing_translations_in("test")
end
|
102
103
104
|
# File 'lib/suspenders/app_builder.rb', line 102
def configure_local_mail
copy_file "email.rb", "config/initializers/email.rb"
end
|
65
66
67
68
69
70
71
|
# File 'lib/suspenders/app_builder.rb', line 65
def configure_quiet_assets
config = <<-RUBY
config.assets.quiet = true
RUBY
inject_into_class "config/application.rb", "Application", config
end
|
170
171
172
173
|
# File 'lib/suspenders/app_builder.rb', line 170
def configure_time_formats
remove_file "config/locales/en.yml"
template "config_locales_en.yml.erb", "config/locales/en.yml"
end
|
#copy_miscellaneous_files ⇒ Object
203
204
205
206
|
# File 'lib/suspenders/app_builder.rb', line 203
def copy_miscellaneous_files
copy_file "errors.rb", "config/initializers/errors.rb"
copy_file "json_encoding.rb", "config/initializers/json_encoding.rb"
end
|
#create_database ⇒ Object
139
140
141
|
# File 'lib/suspenders/app_builder.rb', line 139
def create_database
bundle_command "exec rails db:create db:migrate"
end
|
#create_github_repo(repo_name) ⇒ Object
199
200
201
|
# File 'lib/suspenders/app_builder.rb', line 199
def create_github_repo(repo_name)
run "hub create #{repo_name}"
end
|
#create_heroku_apps(flags) ⇒ Object
189
190
191
192
|
# File 'lib/suspenders/app_builder.rb', line 189
def create_heroku_apps(flags)
create_staging_heroku_app(flags)
create_production_heroku_app(flags)
end
|
#disallow_wrapping_parameters ⇒ Object
130
131
132
|
# File 'lib/suspenders/app_builder.rb', line 130
def disallow_wrapping_parameters
remove_file "config/initializers/wrap_parameters.rb"
end
|
#gemfile ⇒ Object
29
30
31
|
# File 'lib/suspenders/app_builder.rb', line 29
def gemfile
template "Gemfile.erb", "Gemfile"
end
|
#gitignore ⇒ Object
25
26
27
|
# File 'lib/suspenders/app_builder.rb', line 25
def gitignore
copy_file "suspenders_gitignore", ".gitignore"
end
|
#provide_setup_script ⇒ Object
73
74
75
76
|
# File 'lib/suspenders/app_builder.rb', line 73
def provide_setup_script
template "bin_setup", "bin/setup", force: true
run "chmod a+x bin/setup"
end
|
#provide_yarn_script ⇒ Object
78
79
80
81
|
# File 'lib/suspenders/app_builder.rb', line 78
def provide_yarn_script
template "bin_yarn", "bin/yarn", force: true
run "chmod a+x bin/yarn"
end
|
#raise_on_delivery_errors ⇒ Object
44
45
46
47
|
# File 'lib/suspenders/app_builder.rb', line 44
def raise_on_delivery_errors
replace_in_file "config/environments/development.rb",
"raise_delivery_errors = false", "raise_delivery_errors = true"
end
|
#raise_on_missing_assets_in_test ⇒ Object
40
41
42
|
# File 'lib/suspenders/app_builder.rb', line 40
def raise_on_missing_assets_in_test
configure_environment "test", "config.assets.raise_runtime_errors = true"
end
|
#raise_on_unpermitted_parameters ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/suspenders/app_builder.rb', line 57
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
|
#readme ⇒ Object
21
22
23
|
# File 'lib/suspenders/app_builder.rb', line 21
def readme
template "README.md.erb", "README.md"
end
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/suspenders/app_builder.rb', line 208
def
config_files = [
"application.rb",
"environment.rb",
"environments/development.rb",
"environments/production.rb",
"environments/test.rb"
]
config_files.each do |config_file|
path = Pathname(destination_root).join("config", config_file)
source = Actions::StripCommentsAction.call(path.read)
path.write(source)
end
end
|
225
226
227
228
229
|
# File 'lib/suspenders/app_builder.rb', line 225
def
replace_in_file "config/routes.rb",
/Rails\.application\.routes\.draw do.*end/m,
"Rails.application.routes.draw do\nend"
end
|
#replace_gemfile ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'lib/suspenders/app_builder.rb', line 147
def replace_gemfile
template "Gemfile.erb", "Gemfile", force: true do |content|
if development_env?
content.gsub(%r{gem .suspenders.}) { |s| %(#{s}, path: "#{root_path}") }
else
content
end
end
end
|
#ruby_version ⇒ Object
157
158
159
|
# File 'lib/suspenders/app_builder.rb', line 157
def ruby_version
create_file ".ruby-version", "#{Suspenders::RUBY_VERSION}\n"
end
|
#run_database_migrations ⇒ Object
143
144
145
|
# File 'lib/suspenders/app_builder.rb', line 143
def run_database_migrations
bundle_command "exec rails db:migrate"
end
|
#set_test_delivery_method ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/suspenders/app_builder.rb', line 49
def set_test_delivery_method
inject_into_file(
"config/environments/development.rb",
"\n config.action_mailer.delivery_method = :file",
after: "config.action_mailer.raise_delivery_errors = true"
)
end
|
#setup_asset_host ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/suspenders/app_builder.rb', line 106
def setup_asset_host
replace_in_file "config/environments/production.rb",
%(# config.asset_host = "http://assets.example.com"),
'config.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
if File.exist?("config/initializers/assets.rb")
replace_in_file "config/initializers/assets.rb",
%(Rails.application.config.assets.version = "1.0"),
'Rails.application.config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
end
config = <<~EOD
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=31557600",
}
EOD
configure_environment("production", config)
end
|
#setup_default_rake_task ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/suspenders/app_builder.rb', line 231
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_rack_mini_profiler ⇒ Object
33
34
35
36
37
38
|
# File 'lib/suspenders/app_builder.rb', line 33
def setup_rack_mini_profiler
copy_file(
"rack_mini_profiler.rb",
"config/initializers/rack_mini_profiler.rb"
)
end
|
#setup_secret_token ⇒ Object
126
127
128
|
# File 'lib/suspenders/app_builder.rb', line 126
def setup_secret_token
template "secrets.yml", "config/secrets.yml", force: true
end
|
#use_postgres_config_template ⇒ Object
134
135
136
137
|
# File 'lib/suspenders/app_builder.rb', line 134
def use_postgres_config_template
template "postgresql_database.yml.erb", "config/database.yml",
force: true
end
|