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, #replace_in_file
Instance Method Details
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/suspenders/app_builder.rb', line 170
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
|
161
162
163
|
# File 'lib/suspenders/app_builder.rb', line 161
def configure_action_mailer_in_specs
copy_file "action_mailer.rb", "spec/support/action_mailer.rb"
end
|
189
190
191
192
|
# File 'lib/suspenders/app_builder.rb', line 189
def configure_automatic_deployment
append_file "Procfile", "release: bin/auto_migrate\n"
copy_file "bin_auto_migrate", "bin/auto_migrate"
end
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/suspenders/app_builder.rb', line 78
def configure_generators
config = "\nconfig.generators do |generate|\n generate.helper false\n generate.javascripts false\n generate.controller_specs false\n generate.request_specs true\n generate.routing_specs false\n generate.stylesheets false\n generate.test_framework :rspec\n generate.view_specs false\nend\n\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n"
|
156
157
158
159
|
# File 'lib/suspenders/app_builder.rb', line 156
def configure_i18n_for_missing_translations
raise_on_missing_translations_in("development")
raise_on_missing_translations_in("test")
end
|
97
98
99
|
# File 'lib/suspenders/app_builder.rb', line 97
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 = "config.assets.quiet = true\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n"
|
165
166
167
168
|
# File 'lib/suspenders/app_builder.rb', line 165
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
198
199
200
201
|
# File 'lib/suspenders/app_builder.rb', line 198
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
134
135
136
|
# File 'lib/suspenders/app_builder.rb', line 134
def create_database
bundle_command "exec rails db:create db:migrate"
end
|
#create_github_repo(repo_name) ⇒ Object
194
195
196
|
# File 'lib/suspenders/app_builder.rb', line 194
def create_github_repo(repo_name)
run "hub create #{repo_name}"
end
|
#create_heroku_apps(flags) ⇒ Object
184
185
186
187
|
# File 'lib/suspenders/app_builder.rb', line 184
def create_heroku_apps(flags)
create_staging_heroku_app(flags)
create_production_heroku_app(flags)
end
|
#disallow_wrapping_parameters ⇒ Object
125
126
127
|
# File 'lib/suspenders/app_builder.rb', line 125
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
|
#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 = "config.action_controller.action_on_unpermitted_parameters = :raise\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n"
|
#readme ⇒ Object
21
22
23
|
# File 'lib/suspenders/app_builder.rb', line 21
def readme
template "README.md.erb", "README.md"
end
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/suspenders/app_builder.rb', line 203
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::.call(path.read)
path.write(source)
end
end
|
220
221
222
223
224
|
# File 'lib/suspenders/app_builder.rb', line 220
def
replace_in_file "config/routes.rb",
/Rails\.application\.routes\.draw do.*end/m,
"Rails.application.routes.draw do\nend"
end
|
#replace_gemfile(path) ⇒ Object
142
143
144
145
146
147
148
149
150
|
# File 'lib/suspenders/app_builder.rb', line 142
def replace_gemfile(path)
template "Gemfile.erb", "Gemfile", force: true do |content|
if path
content.gsub(%r{gem .suspenders.}) { |s| %(#{s}, path: "#{path}") }
else
content
end
end
end
|
#ruby_version ⇒ Object
152
153
154
|
# File 'lib/suspenders/app_builder.rb', line 152
def ruby_version
create_file ".ruby-version", "#{Suspenders::RUBY_VERSION}\n"
end
|
#run_database_migrations ⇒ Object
138
139
140
|
# File 'lib/suspenders/app_builder.rb', line 138
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/suspenders/app_builder.rb', line 101
def setup_asset_host
replace_in_file "config/environments/production.rb",
"# config.action_controller.asset_host = 'http://assets.example.com'",
'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
if File.exist?("config/initializers/assets.rb")
replace_in_file "config/initializers/assets.rb",
"config.assets.version = '1.0'",
'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
end
config = " config.public_file_server.headers = {\n \"Cache-Control\" => \"public, max-age=31557600\",\n }\n EOD\n\n configure_environment(\"production\", config)\nend\n"
|
#setup_default_rake_task ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/suspenders/app_builder.rb', line 226
def setup_default_rake_task
append_file "Rakefile" do
" task(:default).clear\n task default: [:spec]\n\n if defined? RSpec\n task(:spec).clear\n RSpec::Core::RakeTask.new(:spec) do |t|\n t.verbose = false\n end\n end\n EOS\n end\nend\n"
|
#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
121
122
123
|
# File 'lib/suspenders/app_builder.rb', line 121
def setup_secret_token
template "secrets.yml", "config/secrets.yml", force: true
end
|
#use_postgres_config_template ⇒ Object
129
130
131
132
|
# File 'lib/suspenders/app_builder.rb', line 129
def use_postgres_config_template
template "postgresql_database.yml.erb", "config/database.yml",
force: true
end
|