orats 0.7.3 → 0.8.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/.gitignore +2 -1
  3. data/Gemfile +1 -1
  4. data/{LICENSE.txt → LICENSE} +21 -21
  5. data/README.md +51 -346
  6. data/Rakefile +1 -1
  7. data/bin/orats +5 -2
  8. data/lib/orats/argv_adjust.rb +61 -0
  9. data/lib/orats/cli.rb +53 -141
  10. data/lib/orats/cli_help/new +27 -0
  11. data/lib/orats/cli_help/nuke +19 -0
  12. data/lib/orats/commands/new/exec.rb +59 -0
  13. data/lib/orats/commands/new/rails.rb +197 -0
  14. data/lib/orats/commands/new/server.rb +67 -0
  15. data/lib/orats/commands/nuke.rb +66 -44
  16. data/lib/orats/common.rb +76 -0
  17. data/lib/orats/postgres.rb +90 -0
  18. data/lib/orats/process.rb +35 -0
  19. data/lib/orats/redis.rb +25 -0
  20. data/lib/orats/shell.rb +12 -0
  21. data/lib/orats/templates/auth.rb +96 -82
  22. data/lib/orats/templates/base.rb +115 -110
  23. data/lib/orats/templates/includes/new/rails/.env +28 -28
  24. data/lib/orats/templates/includes/new/rails/Gemfile +4 -4
  25. data/lib/orats/templates/includes/new/rails/config/{whenever.rb → schedule.rb} +0 -0
  26. data/lib/orats/ui.rb +33 -0
  27. data/lib/orats/version.rb +3 -2
  28. data/lib/orats.rb +2 -1
  29. data/orats.gemspec +7 -5
  30. data/test/integration/cli_test.rb +28 -177
  31. data/test/test_helper.rb +24 -9
  32. metadata +17 -29
  33. data/lib/orats/commands/common.rb +0 -146
  34. data/lib/orats/commands/diff/compare.rb +0 -106
  35. data/lib/orats/commands/diff/exec.rb +0 -60
  36. data/lib/orats/commands/diff/parse.rb +0 -66
  37. data/lib/orats/commands/inventory.rb +0 -100
  38. data/lib/orats/commands/playbook.rb +0 -60
  39. data/lib/orats/commands/project/exec.rb +0 -74
  40. data/lib/orats/commands/project/rails.rb +0 -162
  41. data/lib/orats/commands/project/server.rb +0 -57
  42. data/lib/orats/commands/role.rb +0 -70
  43. data/lib/orats/commands/ui.rb +0 -47
  44. data/lib/orats/templates/includes/inventory/group_vars/all.yml +0 -202
  45. data/lib/orats/templates/includes/inventory/hosts +0 -8
  46. data/lib/orats/templates/includes/playbook/Galaxyfile +0 -15
  47. data/lib/orats/templates/includes/playbook/common.yml +0 -23
  48. data/lib/orats/templates/includes/playbook/site.yml +0 -36
  49. data/lib/orats/templates/includes/role/.travis.yml +0 -19
  50. data/lib/orats/templates/includes/role/README.md +0 -62
  51. data/lib/orats/templates/includes/role/meta/main.yml +0 -123
  52. data/lib/orats/templates/includes/role/tests/inventory +0 -1
  53. data/lib/orats/templates/includes/role/tests/main.yml +0 -7
  54. data/lib/orats/templates/playbook.rb +0 -119
  55. data/lib/orats/templates/role.rb +0 -144
@@ -19,31 +19,30 @@ def method_to_sentence(method)
19
19
  method
20
20
  end
21
21
 
22
- def log_task(message)
22
+ def task(message, color = :blue)
23
23
  puts
24
- say_status 'task', "#{method_to_sentence(message.to_s)}:", :yellow
25
- puts '-'*80, ''; sleep 0.25
24
+ say_status 'task', set_color(message, :bold), color
26
25
  end
27
26
 
28
- def git_commit(message)
27
+ def commit(message)
29
28
  git add: '-A'
30
29
  git commit: "-m '#{message}'"
31
30
  end
32
31
 
33
- def migrate(table_name, migration='')
34
- utc_now = Time.now.getutc.strftime("%Y%m%d%H%M%S")
32
+ def migrate(table_name, migration = '')
33
+ utc_now = Time.now.getutc.strftime('%Y%m%d%H%M%S')
35
34
  class_name = table_name.to_s.classify.pluralize
36
35
 
37
- file "db/migrate/#{utc_now}_create_#{table_name}.rb", %{
36
+ file "db/migrate/#{utc_now}_create_#{table_name}.rb", %(
38
37
  class Create#{class_name} < ActiveRecord::Migration
39
38
  def change
40
39
  #{migration}
41
40
  end
42
41
  end
43
- }
42
+ )
44
43
  end
45
44
 
46
- def copy_from_local_gem(source, dest = '')
45
+ def orats_to_local(source, dest = '')
47
46
  dest = source if dest.empty?
48
47
 
49
48
  base_path = "#{File.expand_path File.dirname(__FILE__)}/includes/new/rails"
@@ -59,7 +58,7 @@ def delete_app_css
59
58
  end
60
59
 
61
60
  def update_gemfile
62
- log_task __method__
61
+ task __method__
63
62
 
64
63
  inject_into_file 'Gemfile', before: "\ngem 'kaminari'" do
65
64
  <<-S
@@ -69,11 +68,11 @@ gem 'devise-async', '~> 0.9.0'
69
68
  gem 'pundit', '~> 0.2.3'
70
69
  S
71
70
  end
72
- git_commit 'Add authentication related gems'
71
+ commit 'Add authentication related gems'
73
72
  end
74
73
 
75
74
  def update_dotenv
76
- log_task __method__
75
+ task __method__
77
76
 
78
77
  inject_into_file '.env', before: "\nSMTP_ADDRESS" do
79
78
  <<-CODE
@@ -87,34 +86,37 @@ TOKEN_DEVISE_PEPPER: #{generate_token}
87
86
  ACTION_MAILER_DEVISE_DEFAULT_FROM: info@#{app_name}.com
88
87
  CODE
89
88
  end
90
- git_commit 'Add devise tokens and default e-mail'
89
+ commit 'Add devise tokens and default e-mail'
91
90
  end
92
91
 
93
92
  def run_bundle_install
94
- log_task __method__
93
+ task __method__
95
94
 
96
95
  run 'bundle install'
97
96
  end
98
97
 
99
98
  def add_pundit
100
- log_task __method__
99
+ task __method__
101
100
 
102
101
  generate 'pundit:install'
103
- inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do
102
+ inject_into_file 'app/controllers/application_controller.rb',
103
+ after: "::Base\n" do
104
104
  <<-S
105
105
  include Pundit
106
106
 
107
107
  S
108
108
  end
109
109
 
110
- inject_into_file 'app/controllers/application_controller.rb', after: ":exception\n" do
110
+ inject_into_file 'app/controllers/application_controller.rb',
111
+ after: ":exception\n" do
111
112
  <<-S
112
113
 
113
114
  rescue_from Pundit::NotAuthorizedError, with: :account_not_authorized
114
115
  S
115
116
  end
116
117
 
117
- inject_into_file 'app/controllers/application_controller.rb', after: " #end\n" do
118
+ inject_into_file 'app/controllers/application_controller.rb',
119
+ after: " #end\n" do
118
120
  <<-S
119
121
 
120
122
  def account_not_authorized
@@ -122,55 +124,63 @@ def add_pundit
122
124
  end
123
125
  S
124
126
  end
125
- git_commit 'Add pundit policy and controller logic'
127
+ commit 'Add pundit policy and controller logic'
126
128
  end
127
129
 
128
130
  def add_devise_initializers
129
- log_task __method__
131
+ task __method__
130
132
 
131
- copy_from_local_gem 'config/initializers/devise_async.rb'
133
+ orats_to_local 'config/initializers/devise_async.rb'
132
134
  generate 'devise:install'
133
- git_commit 'Add the devise and devise async initializers'
135
+ commit 'Add the devise and devise async initializers'
134
136
  end
135
137
 
136
138
  def update_devise_initializer
137
- log_task 'Update the devise initializer'
139
+ task 'Update the devise initializer'
138
140
 
139
141
  gsub_file 'config/initializers/devise.rb',
140
- "'please-change-me-at-config-initializers-devise@example.com'", "ENV['ACTION_MAILER_DEVISE_DEFAULT_EMAIL']"
141
- gsub_file 'config/initializers/devise.rb', /(?<=key = )'\w{128}'/, "ENV['TOKEN_DEVISE_SECRET']"
142
- gsub_file 'config/initializers/devise.rb', /(?<=pepper = )'\w{128}'/, "ENV['TOKEN_DEVISE_PEPPER']"
143
- gsub_file 'config/initializers/devise.rb', '# config.timeout_in = 30.minutes',
142
+ "'please-change-me-at-config-initializers-devise@example.com'",
143
+ "ENV['ACTION_MAILER_DEVISE_DEFAULT_EMAIL']"
144
+ gsub_file 'config/initializers/devise.rb', /(?<=key = )'\w{128}'/,
145
+ "ENV['TOKEN_DEVISE_SECRET']"
146
+ gsub_file 'config/initializers/devise.rb', /(?<=pepper = )'\w{128}'/,
147
+ "ENV['TOKEN_DEVISE_PEPPER']"
148
+ gsub_file 'config/initializers/devise.rb',
149
+ '# config.timeout_in = 30.minutes',
144
150
  'config.timeout_in = 2.hours'
145
151
 
146
- gsub_file 'config/initializers/devise.rb', '# config.expire_auth_token_on_timeout = false',
152
+ gsub_file 'config/initializers/devise.rb',
153
+ '# config.expire_auth_token_on_timeout = false',
147
154
  'config.expire_auth_token_on_timeout = true'
148
- gsub_file 'config/initializers/devise.rb', '# config.lock_strategy = :failed_attempts',
155
+ gsub_file 'config/initializers/devise.rb',
156
+ '# config.lock_strategy = :failed_attempts',
149
157
  'config.lock_strategy = :failed_attempts'
150
- gsub_file 'config/initializers/devise.rb', '# config.unlock_strategy = :both',
158
+ gsub_file 'config/initializers/devise.rb',
159
+ '# config.unlock_strategy = :both',
151
160
  'config.unlock_strategy = :both'
152
161
  gsub_file 'config/initializers/devise.rb', '# config.maximum_attempts = 20',
153
162
  'config.maximum_attempts = 7'
154
163
  gsub_file 'config/initializers/devise.rb', '# config.unlock_in = 1.hour',
155
164
  'config.unlock_in = 2.hours'
156
- gsub_file 'config/initializers/devise.rb', '# config.last_attempt_warning = false',
165
+ gsub_file 'config/initializers/devise.rb',
166
+ '# config.last_attempt_warning = false',
157
167
  'config.last_attempt_warning = true'
158
- git_commit 'Update the devise defaults'
168
+ commit 'Update the devise defaults'
159
169
  end
160
170
 
161
171
  def update_sidekiq_config
162
- log_task __method__
172
+ task __method__
163
173
 
164
174
  append_file 'config/sidekiq.yml' do
165
175
  <<-S
166
176
  - mailer
167
177
  S
168
178
  end
169
- git_commit 'Add the devise mailer queue to sidekiq'
179
+ commit 'Add the devise mailer queue to sidekiq'
170
180
  end
171
181
 
172
182
  def update_routes
173
- log_task __method__
183
+ task __method__
174
184
 
175
185
  gsub_file 'config/routes.rb', "mount Sidekiq::Web => '/sidekiq'\n", ''
176
186
  inject_into_file 'config/routes.rb', after: "collection\n end\n" do
@@ -191,11 +201,11 @@ def update_routes
191
201
 
192
202
  S
193
203
  end
194
- git_commit 'Add the devise route and protect sidekiq with authentication'
204
+ commit 'Add the devise route and protect sidekiq with authentication'
195
205
  end
196
206
 
197
207
  def add_en_locale_for_authorization
198
- log_task __method__
208
+ task __method__
199
209
 
200
210
  gsub_file 'config/locales/en.yml', "hello: \"Hello world\"\n", ''
201
211
  append_file 'config/locales/en.yml' do
@@ -204,11 +214,11 @@ authorization:
204
214
  error: 'You are not authorized to perform this action.'
205
215
  S
206
216
  end
207
- git_commit 'Add en locale entry for authorization errors'
217
+ commit 'Add en locale entry for authorization errors'
208
218
  end
209
219
 
210
220
  def add_devise_migration
211
- log_task __method__
221
+ task __method__
212
222
 
213
223
  migrate :accounts, %{
214
224
  create_table(:accounts) do |t|
@@ -245,26 +255,27 @@ def add_devise_migration
245
255
  add_index :accounts, :reset_password_token, :unique => true
246
256
  add_index :accounts, :unlock_token, :unique => true
247
257
  }
248
- git_commit 'Add devise model migration'
258
+ commit 'Add devise model migration'
249
259
  end
250
260
 
251
261
  def add_account_model
252
- log_task __method__
262
+ task __method__
253
263
 
254
- copy_from_local_gem 'app/models/account.rb'
255
- git_commit 'Add account model'
264
+ orats_to_local 'app/models/account.rb'
265
+ commit 'Add account model'
256
266
  end
257
267
 
258
268
  def add_seed_user
259
- log_task __method__
269
+ task __method__
260
270
 
261
- append_file 'db/seeds.rb', "\nAccount.create({ email: \"admin@#{app_name}.com\", password: \"password\",
271
+ append_file 'db/seeds.rb', "\nAccount.create({ email: " + \
272
+ " \"admin@#{app_name}.com\", password: \"password\",
262
273
  role: \"admin\" })"
263
- git_commit 'Add seed user'
274
+ commit 'Add seed user'
264
275
  end
265
276
 
266
277
  def update_test_helper
267
- log_task __method__
278
+ task __method__
268
279
  inject_into_file 'test/test_helper.rb', after: "end\n" do
269
280
  <<-S
270
281
 
@@ -273,37 +284,39 @@ class ActionController::TestCase
273
284
  end
274
285
  S
275
286
  end
276
- git_commit 'Add devise test helper'
287
+ commit 'Add devise test helper'
277
288
  end
278
289
 
279
290
  def add_account_fixtures
280
- log_task __method__
281
- copy_from_local_gem 'test/fixtures/accounts.yml'
282
- git_commit 'Add account fixtures'
291
+ task __method__
292
+ orats_to_local 'test/fixtures/accounts.yml'
293
+ commit 'Add account fixtures'
283
294
  end
284
295
 
285
296
  def add_account_unit_tests
286
- log_task __method__
297
+ task __method__
287
298
 
288
- copy_from_local_gem 'test/models/account_test.rb'
289
- git_commit 'Add account unit tests'
299
+ orats_to_local 'test/models/account_test.rb'
300
+ commit 'Add account unit tests'
290
301
  end
291
302
 
292
303
  def add_current_user_alias
293
- log_task __method__
304
+ task __method__
294
305
 
295
- inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do
306
+ inject_into_file 'app/controllers/application_controller.rb',
307
+ after: "::Base\n" do
296
308
  <<-S
297
309
  alias_method :current_user, :current_account
298
310
 
299
311
  S
300
312
  end
301
- git_commit 'Add current_user alias'
313
+ commit 'Add current_user alias'
302
314
  end
303
315
 
304
316
  def add_devise_controller_override
305
- log_task __method__
306
- inject_into_file 'app/controllers/application_controller.rb', before: "end\n" do
317
+ task __method__
318
+ inject_into_file 'app/controllers/application_controller.rb',
319
+ before: "end\n" do
307
320
  <<-S
308
321
 
309
322
  private
@@ -318,32 +331,33 @@ def add_devise_controller_override
318
331
  #end
319
332
  S
320
333
  end
321
- git_commit 'Add devise after_sign_in_path_for override'
334
+ commit 'Add devise after_sign_in_path_for override'
322
335
  end
323
336
 
324
337
  def add_devise_views
325
- log_task __method__
326
-
327
- copy_from_local_gem 'app/views/devise/confirmations/new.html.erb'
328
- copy_from_local_gem 'app/views/devise/mailer/confirmation_instructions.html.erb'
329
- copy_from_local_gem 'app/views/devise/mailer/confirmation_instructions.html.erb'
330
- copy_from_local_gem 'app/views/devise/mailer/reset_password_instructions.html.erb'
331
- copy_from_local_gem 'app/views/devise/mailer/unlock_instructions.html.erb'
332
- copy_from_local_gem 'app/views/devise/passwords/edit.html.erb'
333
- copy_from_local_gem 'app/views/devise/passwords/new.html.erb'
334
- copy_from_local_gem 'app/views/devise/registrations/edit.html.erb'
335
- copy_from_local_gem 'app/views/devise/registrations/new.html.erb'
336
- copy_from_local_gem 'app/views/devise/sessions/new.html.erb'
337
- copy_from_local_gem 'app/views/devise/unlocks/new.html.erb'
338
- copy_from_local_gem 'app/views/devise/shared/_links.html.erb'
339
- git_commit 'Add devise views'
338
+ task __method__
339
+
340
+ orats_to_local 'app/views/devise/confirmations/new.html.erb'
341
+ orats_to_local 'app/views/devise/mailer/confirmation_instructions.html.erb'
342
+ orats_to_local 'app/views/devise/mailer/confirmation_instructions.html.erb'
343
+ orats_to_local 'app/views/devise/mailer/reset_password_instructions.html.erb'
344
+ orats_to_local 'app/views/devise/mailer/unlock_instructions.html.erb'
345
+ orats_to_local 'app/views/devise/passwords/edit.html.erb'
346
+ orats_to_local 'app/views/devise/passwords/new.html.erb'
347
+ orats_to_local 'app/views/devise/registrations/edit.html.erb'
348
+ orats_to_local 'app/views/devise/registrations/new.html.erb'
349
+ orats_to_local 'app/views/devise/sessions/new.html.erb'
350
+ orats_to_local 'app/views/devise/unlocks/new.html.erb'
351
+ orats_to_local 'app/views/devise/shared/_links.html.erb'
352
+ commit 'Add devise views'
340
353
  end
341
354
 
342
355
  def add_auth_links_to_the_navbar
343
- log_task __method__
356
+ task __method__
344
357
 
345
- copy_from_local_gem 'app/views/layouts/_navigation_auth.html.erb'
346
- inject_into_file 'app/views/layouts/_navigation.html.erb', after: "</ul>\n" do
358
+ orats_to_local 'app/views/layouts/_navigation_auth.html.erb'
359
+ inject_into_file 'app/views/layouts/_navigation.html.erb',
360
+ after: "</ul>\n" do
347
361
  <<-S
348
362
  <ul class="nav navbar-nav nav-auth">
349
363
  <%= render 'layouts/navigation_auth' %>
@@ -361,14 +375,14 @@ def add_auth_links_to_the_navbar
361
375
  }
362
376
  S
363
377
  end
364
- git_commit 'Add authentication links to the layout'
378
+ commit 'Add authentication links to the layout'
365
379
  end
366
380
 
367
381
  def remove_unused_files_from_git
368
- log_task __method__
382
+ task __method__
369
383
 
370
384
  git add: '-u'
371
- git_commit 'Remove unused files'
385
+ commit 'Remove unused files'
372
386
  end
373
387
 
374
388
  # ---
@@ -393,4 +407,4 @@ add_current_user_alias
393
407
  add_devise_controller_override
394
408
  add_devise_views
395
409
  add_auth_links_to_the_navbar
396
- remove_unused_files_from_git
410
+ remove_unused_files_from_git