myrails 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7af89ba21720951b5f321eaa480e657d524b16c9
4
- data.tar.gz: d3a11a743f04736f6ce534a0ef48543d00616732
2
+ SHA256:
3
+ metadata.gz: 8450b1df8a8d157e8f7dbe333953599cb38350e97f57fad2105c6d121ed48e4a
4
+ data.tar.gz: a06d4fef3fdfac38da6c9e1edb3295fc99abdfe0ce0995bb7851bb02c6efd957
5
5
  SHA512:
6
- metadata.gz: dd366e4bc56d862be02e2f68669b80dfcf7a2dcd2fba3f3e49c860c3ab64f31167352bce9840dfc30b9d04b3556e09c931c0c61cbf51034a3fb9e8f35c9498ed
7
- data.tar.gz: e5889ff4a08db266f0e18ed64e4e35e4382650910c1b900b82a96b2142fe79e91bcef8d02ec54077012ff10aaa7e0cb7da468aaaddd3d86536e603996792a960
6
+ metadata.gz: 136f26e0eaf3bb7c1d227c91be28497f100e936751372547c01fd35bf5d36a032954ef413d774d99d8b201b136b1a3c9a043f0f6194cab019cea836acdc5192b
7
+ data.tar.gz: 89eb02894b6d8757220d786dd050df8192755dc838a66f869c7efcdd63b0f02b0cf034220838cc9382689dd87e14d221284dd5e00cb320cd5c8bdadbcf681a2f
data/lib/myrails.rb CHANGED
@@ -1,7 +1,24 @@
1
1
  require 'thor'
2
2
  require 'active_support/all'
3
3
  require_relative "../lib/myrails/version"
4
-
4
+ require_relative 'myrails/modules/gems'
5
+ require_relative 'myrails/modules/bootstrap'
6
+ require_relative 'myrails/modules/material'
7
+ require_relative 'myrails/modules/ui'
8
+ require_relative 'myrails/modules/assets'
9
+ require_relative 'myrails/modules/application'
10
+ require_relative 'myrails/modules/capistrano'
11
+ require_relative 'myrails/modules/database'
12
+ require_relative 'myrails/modules/devise'
13
+ require_relative 'myrails/modules/dotenv'
14
+ require_relative 'myrails/modules/engine'
15
+ require_relative 'myrails/modules/figaro'
16
+ require_relative 'myrails/modules/footnotes'
17
+ require_relative 'myrails/modules/heroku'
18
+ require_relative 'myrails/modules/pundit'
19
+ require_relative 'myrails/modules/rails_generators'
20
+ require_relative 'myrails/modules/rspec_generators'
21
+ require_relative 'myrails/modules/rspec'
5
22
  module Myrails
6
23
  class Myrails < Thor
7
24
  include Thor::Actions
@@ -10,165 +27,20 @@ module Myrails
10
27
  ENVIRONMENTS = %w(development test production)
11
28
 
12
29
  no_tasks do
13
- desc 'install_application_helper', 'Replace current application helper with one that has commonly used code'
14
- def install_application_helper
15
- copy_file 'rails/app/helpers/application_helper.rb', 'app/helpers/application_helper.rb'
16
- end
17
-
18
- desc 'install_gems', 'Add & Install gems that I commonly use'
19
- def install_gems
20
- insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
21
- group :test do
22
- gem 'simplecov'
23
- gem 'shoulda-matchers'
24
- gem 'factory_bot_rails'
25
- gem 'database_cleaner'
26
- gem 'chromedriver-helper'
27
- gem 'launchy'
28
- gem 'rails-controller-testing'
29
- end
30
- CODE
31
- end
32
-
33
- insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
34
- gem 'faker'
35
- gem 'yard'
36
- gem 'letter_opener'
37
- gem "rails-erd"
38
- CODE
39
- end
40
-
41
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
42
- gem 'haml-rails'
43
- gem "ransack"
44
- gem 'will_paginate'
45
- gem "font-awesome-rails"
46
- gem 'trix'
47
- gem 'record_tag_helper'
48
- gem 'jquery-rails'
49
- CODE
50
- end
51
- run 'bundle install'
52
-
53
- insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
54
- private
55
- CODE
56
- end
57
- end
58
-
59
- desc 'install_assets', 'Generate common asset pipeline files'
60
- def install_assets
61
- run "rm app/assets/stylesheets/application.css"
62
- copy_file 'rails/app/assets/stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
63
- copy_file 'rails/app/assets/javascripts/application.js', 'app/assets/javascripts/application.js'
64
- copy_file 'rails/app/assets/stylesheets/animate.scss', 'app/assets/stylesheets/animate.scss'
65
- copy_file 'rails/app/assets/stylesheets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
66
- end
67
-
68
-
69
- def choose_bootstrap_theme
70
- themes = Dir[File.join(TEMPLATES, 'rails', 'app','assets', 'stylesheets', 'bootstrap', 'bootstrap_themes', '*')]
71
-
72
- themes.each_with_index do |theme, index|
73
- say "[#{index}] #{File.basename(theme,'.*')}"
74
- end
75
-
76
- idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
77
- idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
78
-
79
- copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
80
-
81
- inject_into_file 'app/assets/stylesheets/application.css.sass', before: "@import will_paginate" do <<-CODE
82
- @import #{File.basename(themes[idx], '.*')}
83
- CODE
84
- end
85
- end
86
-
87
- def choose_bootstrap_footer
88
- footers = Dir[File.join(TEMPLATES, 'rails', 'app', 'views','layout', 'bootstrap', 'footers', '*.haml')]
89
- footers_css = Dir[File.join(TEMPLATES, 'rails', 'app', 'views', 'layout', 'bootstrap', 'footers', 'css', '*')]
90
-
91
- footers.each_with_index do |footer, index|
92
- say "[#{index}] #{File.basename(footer,'.html.*')}"
93
- end
94
-
95
- idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
96
- idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
97
- copy_file footers[idx], "app/views/layouts/_footer.html.haml"
98
- copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
99
-
100
- inject_into_file 'app/assets/stylesheets/application.css.sass', after: "@import animate\n" do <<-CODE
101
- @import #{File.basename(footers_css[idx], '.*')}
102
- CODE
103
- end
104
- end
105
-
106
- def copy_bootstrap_files
107
- template 'rails/app/views/layout/bootstrap/application.html.haml', 'app/views/layouts/application.html.haml'
108
- template 'rails/app/views/layout/bootstrap/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
109
- copy_file 'rails/app/views/layout/bootstrap/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
110
- copy_file 'rails/app/views/layout/bootstrap/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
111
- copy_file 'rails/app/views/layout/bootstrap/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
112
- # copy_file 'rails/app/views/layout/bootstrap/_footer.html.haml', 'app/views/layouts/_footer.html.haml'
113
- end
114
-
115
- desc 'install_bootstrap', 'Generate Bootrap css theme'
116
- def install_bootstrap
117
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
118
- gem 'bootstrap-sass', '~> 3.3.1'
119
- gem 'autoprefixer-rails'
120
- CODE
121
- end
122
-
123
- insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
124
- @import bootstrap-sprockets
125
- @import bootstrap
126
- CODE
127
- end
128
-
129
- insert_into_file 'app/assets/javascripts/application.js', before: '//= require trix' do <<-CODE
130
- //= require bootstrap-sprockets
131
- CODE
132
- end
133
- run 'bundle install'
134
- choose_bootstrap_theme
135
- choose_bootstrap_footer
136
- copy_bootstrap_files
137
-
138
- end
139
-
140
- def copy_material_files
141
- Dir["#{__dir__}/myrails/templates/rails/app/views/layout/material/**/*"].each do |file|
142
- copy_file file, "app/views/layouts/#{File.basename(file)}"
143
- end
144
- end
145
-
146
- desc 'install_material', 'Generate Material css theme'
147
- def install_material
148
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
149
- gem 'materialize-sass'
150
- gem 'material_icons'
151
- CODE
152
- end
153
-
154
- run 'bundle install'
155
-
156
- copy_material_files
157
-
158
- insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
159
- @import "materialize/components/color"
160
- $primary-color: color("grey", "darken-3") !default
161
- $secondary-color: color("grey", "base") !default
162
- @import materialize
163
- @import material_icons
164
- CODE
165
- end
166
-
167
- insert_into_file 'app/assets/javascripts/application.js', before: "//= require trix" do <<-CODE
168
- //= require materialize
169
- CODE
170
- end
171
- end
30
+ include Install::Gems
31
+ include Install::Ui
32
+ include Install::ApplicationHelper
33
+ include Install::RSpec
34
+ include Install::Devise
35
+ include Install::Pundit
36
+ include Install::Footnotes
37
+ include Install::DotEnv
38
+ include Install::Heroku
39
+ include Install::Capistrano
40
+ include Install::Assets
41
+ include Install::Figaro
42
+ include Layout::Bootstrap
43
+ include Layout::Material
172
44
 
173
45
  desc 'install_layout', 'Generate common layout files'
174
46
  def install_layout
@@ -190,21 +62,6 @@ CODE
190
62
  end
191
63
  end
192
64
 
193
- desc 'install_heroku', 'setup application for use with heroku using sqlite3 for development'
194
- def install_heroku
195
- insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
196
- group :production do
197
- gem 'pg'
198
- gem 'rails_12factor'
199
- end
200
-
201
- CODE
202
- end
203
- copy_file 'db/sqlite3_database.yml', 'config/database.yml'
204
- copy_file 'heroku/Procfile', 'Procfile'
205
- copy_file 'heroku/puma.rb', 'config/puma.rb'
206
- end
207
-
208
65
  desc 'git_init', "Initialize git with some files automatically ignored"
209
66
  def git_init
210
67
  run 'git init'
@@ -214,192 +71,6 @@ CODE
214
71
  run "git commit -m 'initial commit'"
215
72
  end
216
73
 
217
- desc 'install_ui', 'Generate UI files and code for prototyping views in app/views/ui'
218
- def install_ui
219
- copy_file 'ui/ui_controller.rb', 'app/controllers/ui_controller.rb'
220
- copy_file 'ui/index.html.haml', 'app/views/ui/index.html.haml'
221
- inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-CODE
222
- # Requires an application restart everytime a new page is added.
223
- Dir.glob('app/views/ui/*.html.haml').sort.each do |file|
224
- action = File.basename(file,'.html.haml')
225
- get \"ui/\#{action}\", controller: 'ui', action: action
226
- end
227
- CODE
228
- end
229
- end
230
-
231
- desc 'install_rspec', 'Generate rspec structure & rspec configuration that I commonly use'
232
- def install_rspec
233
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
234
- gem 'rspec-rails', group: :test
235
- CODE
236
- end
237
-
238
- run 'bundle install'
239
- run 'rails g rspec:install'
240
-
241
- install_rails_helper
242
-
243
- Dir["#{__dir__}/myrails/templates/spec/**/*"].each do |file|
244
- if file.include?('/support/') && !['devise'].include?(File.basename(file, '.rb'))
245
- copy_file file, "#{file.gsub(__dir__+'/myrails/templates/', '')}" unless File.directory? file
246
- end
247
- end
248
- end
249
-
250
- desc 'install_rails_helper', 'Add code to rspec/rails_helper so rspec runs the way I like'
251
- def install_rails_helper
252
- inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
253
- require 'simplecov'
254
- SimpleCov.start
255
-
256
- Capybara.app_host = "http://localhost:3000"
257
- Capybara.server_host = "localhost"
258
- Capybara.server_port = "3000"
259
-
260
- #use Chromedriver
261
- unless ENV['NOCHROME']
262
- Capybara.register_driver :selenium do |app|
263
- Capybara::Selenium::Driver.new(app, :browser => :chrome)
264
- end
265
- end
266
- CODE
267
- end
268
-
269
- gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }"
270
-
271
- gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
272
-
273
- inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
274
- # Can use methods like dom_id in features
275
- config.include ActionView::RecordIdentifier, type: :feature
276
- # Can use methods likke strip_tags in features
277
- config.include ActionView::Helpers::SanitizeHelper, type: :feature
278
- # Can use methods like truncate
279
- config.include ActionView::Helpers::TextHelper, type: :feature
280
- config.include(JavascriptHelper, type: :feature)
281
- config.include MailerHelper
282
- CODE
283
- end
284
- end
285
-
286
- desc 'install_devise', 'Generate devise files'
287
- def install_devise
288
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
289
- gem 'devise'
290
- CODE
291
- end
292
- run 'bundle update'
293
- copy_file 'spec/support/configs/devise.rb', 'spec/support/configs/devise.rb'
294
-
295
- devise_model = ask("What would you like to call the devise model? Default: user")
296
- devise_model = devise_model.empty? ? 'user' : devise_model
297
- run 'rails generate devise:install'
298
- run 'rake db:migrate'
299
- run "rails generate devise #{devise_model}"
300
- run 'rails generate devise:views'
301
-
302
- gsub_file 'app/controllers/application_controller.rb', "protect_from_forgery with: :exception", "protect_from_forgery"
303
- inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery\n" do <<-CODE
304
- # Devise authentication method
305
- before_action :authenticate_#{devise_model}!
306
- CODE
307
- end
308
-
309
- if File.exist?('app/controllers/ui_controller.rb')
310
- inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
311
- skip_before_action :authenticate_#{devise_model}!
312
- CODE
313
- end
314
- end
315
-
316
- if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
317
- inject_into_file 'app/controllers/application_controller.rb', after: "before_action :authenticate_#{devise_model}!\n" do <<-CODE
318
- # Before action include additional registration params
319
- # (see #configure_permitted_parameters)
320
- before_action :configure_permitted_parameters, if: :devise_controller?
321
- CODE
322
- end
323
-
324
- inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
325
- # Register additional registration params
326
- def configure_permitted_parameters
327
- devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :attribute])
328
- end
329
- CODE
330
- end
331
- end
332
- end
333
-
334
- desc 'install_pundit', 'Install pundit gem and generate pundit files and application controller code'
335
- def install_pundit
336
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
337
- gem 'pundit'
338
- CODE
339
- end
340
-
341
- insert_into_file 'Gemfile', after: "group :test do\n" do <<-CODE
342
- gem 'pundit-matchers', '~> 1.1.0'
343
- CODE
344
- end
345
-
346
- run 'bundle update'
347
- run 'rails g pundit:install'
348
-
349
- inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-CODE
350
- # Add pundit authorization
351
- include Pundit
352
- CODE
353
- end
354
-
355
- inject_into_file 'app/controllers/application_controller.rb', after: "rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized\n" do <<-CODE
356
- # Rescue from pundit error
357
- # (see #user_not_authorized)
358
- rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
359
- CODE
360
- end
361
-
362
- inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
363
- # Method to gracefully let a user know they are are not authorized
364
- #
365
- # @return flash [Hash] the action notice
366
- def user_not_authorized
367
- flash[:alert] = "You are not authorized to perform this action."
368
- redirect_to home_path
369
- end
370
- CODE
371
- end
372
- end
373
-
374
- desc 'install_footnotes', 'Install rails-footnotes and run its generator'
375
- def install_footnotes
376
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
377
- gem 'rails-footnotes'
378
- CODE
379
- end
380
- run 'bundle install'
381
- run 'rails generate rails_footnotes:install'
382
- end
383
-
384
- desc 'install_dotenv', 'Install dotenv gem'
385
- def install_dotenv
386
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
387
- gem 'dotenv-rails', groups: [:development, :test]
388
- CODE
389
- end
390
-
391
- run 'bundle install'
392
-
393
- inject_into_file 'config.ru', after: "require_relative 'config/environment'\n" do <<-CODE
394
- require 'dotenv'
395
- Dotenv.load
396
- CODE
397
- end
398
- copy_file 'rails/env.config', '.env.development'
399
- copy_file 'rails/env.config', '.env.test'
400
- run 'touch .env.production'
401
- end
402
-
403
74
  desc 'base_install', 'Run the most common actions in the right order'
404
75
  def base_install
405
76
  install_gems
@@ -418,319 +89,14 @@ CODE
418
89
  say 'Dont forget to run config_env'
419
90
  end
420
91
 
421
-
422
-
423
- def install_capistrano
424
- insert_into_file 'Gemfile', after: "group :development do\n" do <<-CODE
425
- gem 'capistrano', '~> 3.6', group: :development
426
- gem 'capistrano-rails', '~> 1.3', group: :development
427
- gem 'capistrano-rvm', group: :development
428
- CODE
429
- end
430
-
431
- run 'bundle install'
432
- run 'bundle exec cap install'
433
- gsub_file 'Capfile', '# require "capistrano/rvm"', 'require "capistrano/rvm"'
434
- gsub_file 'config/deploy.rb', '# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp', 'ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp'
435
- gsub_file 'config/deploy.rb', '# set :deploy_to, "/var/www/my_app_name"', 'set :deploy_to, "/var/www/#{fetch(:application)}"'
436
- gsub_file 'config/deploy.rb', '# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"', 'append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"'
437
-
438
- run 'mkdir -p config/deploy/templates/maintenance'
439
-
440
- Dir["#{__dir__}/myrails/templates/capistrano/**/*"].each do |file|
441
- copy_file file, "#{file.gsub(__dir__+'/myrails/templates/capistrano/', '')}" unless File.directory? file
442
- end
443
-
444
- insert_into_file 'config/deploy.rb', before: '# Default branch is :master' do <<-CODE
445
- set :deploy_via, :remote_cache
446
- set :ssh_options, {forward_agent: true}
447
- CODE
448
- end
449
- insert_into_file 'Capfile', after: "require \"capistrano/rvm\"\n" do <<-CODE
450
- require "capistrano/rails"
451
- CODE
452
- end
453
- insert_into_file 'config/deploy.rb', after: "# set :ssh_options, verify_host_key: :secure\n" do <<-CODE
454
- namespace :deploy do
455
- # after :restart, :clear_cache do
456
- # on roles(:app), in: :groups, limit: 3, wait: 10 do
457
- # # Here we can do anything such as:
458
- # # within release_path do
459
- # # execute :rake, 'cache:clear'
460
- # # end
461
- # end
462
- # end
463
- before :finishing, :restart do
464
- on roles(:app) do
465
- invoke 'unicorn:restart'
466
- invoke 'nginx:restart'
467
- end
468
- end
469
-
470
- task :upload_app_yml do
471
- on roles(:app) do
472
- info 'Uploading application.yml'
473
- upload!("\#{Dir.pwd}/config/application.yml", "\#{fetch(:release_path)}/config")
474
- end
475
- end
476
-
477
- before :starting, 'maintenance:on'
478
- before :starting, 'monit:stop'
479
- before :compile_assets, :upload_app_yml
480
- before :published, 'nginx:create_nginx_config'
481
- before :published, 'unicorn:create_unicorn_config'
482
- before :published,'unicorn:create_unicorn_init'
483
- after :restart, 'monit:create_monit_conf'
484
- after :finished, 'monit:start'
485
- after :finished, 'maintenance:off'
486
- end
487
- CODE
488
- end
489
-
490
- insert_into_file 'config/deploy/production.rb', before: "# role-based syntax" do <<-CODE
491
- set :fqdn,'domain.com'
492
- CODE
493
- end
494
-
495
- insert_into_file 'config/deploy/staging.rb', before: "# role-based syntax" do <<-CODE
496
- set :fqdn,'domain.com'
497
- CODE
498
- end
499
- end
500
-
501
- def install_figaro
502
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
503
- gem "figaro"
504
- CODE
505
- end
506
-
507
- run 'bundle install'
508
- run 'bundle exec figaro install'
509
- copy_file 'rails/config/application.example.yml', 'config/application.example.yml'
510
- end
511
-
512
92
  end
513
93
  # end of no_tasks
94
+ include Rails::Generators
95
+ include RSpec::Generators
96
+ include Rails::Engines
97
+ include Rails::Database
514
98
 
515
- desc 'model', "Generates a rails model with the given name along with its related spec file and namespace prefix for table creation. Use '/' to create a namespaced model"
516
- option :name, required: true
517
- def model
518
- template 'rails/app/models/model.rb', "app/models/#{options[:name].downcase}.rb"
519
- template 'rails/app/models/namespace_model.rb', "app/models/#{options[:name].split("/").first.singularize.downcase}.rb" if options[:name].include?("/")
520
- template 'spec/model.rb', "spec/models/#{options[:name].downcase}_spec.rb"
521
- end
522
-
523
- desc 'controller', "Generates a rails controller with the given name along with related spec file. Use '/' to create a namespaced controller"
524
- option :name, required: true
525
- def controller
526
- template 'rails/app/controllers/controller.rb', "app/controllers/#{options[:name].downcase.pluralize}_controller.rb"
527
- if options[:name].include?("/")
528
- parent, child = options[:name].split("/")
529
- template 'rails/app/controllers/namespace_controller.rb', "app/controllers/#{parent}/#{parent.downcase}_controller.rb"
530
- end
531
- template 'spec/controller.rb', "spec/controllers/#{options[:name].downcase.pluralize}_controller_spec.rb"
532
- run "mkdir -p app/views/#{options[:name].downcase.pluralize}"
533
- end
534
-
535
- desc 'policy', "Generates a pundit policy with the given name and a related spec file. Use '/' to create a namespaced policy"
536
- option :name, required: true
537
- def policy
538
- template 'rails/app/policies/pundit.rb', "app/policies/#{options[:name].downcase}_policy.rb"
539
- template 'spec/pundit.rb', "spec/policies/#{options[:name].downcase}_policy_spec.rb"
540
- end
541
-
542
- desc 'presenter', "Generates a presenter class with the given name and a related spec file. Use '/' to create a namespaced presenter"
543
- option :name, required: true
544
- def presenters
545
- copy_file 'rails/app/presenters/base.rb', 'app/presenters/base_presenter.rb'
546
- template 'rails/app/presenters/presenter.rb', "app/presenters/#{options[:name].downcase}_presenter.rb"
547
- copy_file 'rails/app/presenters/presenter_config.rb', 'spec/support/configs/presenter.rb'
548
- template 'rails/app/presenters/presenter_spec.rb', "spec/presenters/#{options[:name].downcase}_presenter_spec.rb"
549
- end
550
-
551
- desc 'factory', "Generates a factory_bot factory in the spec/factories directory. Use '/' to create a namespaced factory"
552
- option :name, required: true
553
- def factory
554
- template 'spec/factory.rb', "spec/factories/#{options[:name].downcase}.rb"
555
- end
556
-
557
- desc 'sendgrid', 'Generate sendgrid initializer and mail interceptor'
558
- option :email, required: true
559
- def sendgrid
560
- copy_file 'rails/app/mailers/sendgrid.rb', 'config/initializers/sendgrid.rb'
561
- template 'rails/app/mailers/dev_mail_interceptor.rb', 'app/mailers/dev_mail_interceptor.rb'
562
- ENVIRONMENTS.each do |environment|
563
- unless environment == 'production'
564
- inject_into_file "config/environments/#{environment}.rb", after: "Rails.application.configure do\n" do <<-CODE
565
- ActionMailer::Base.register_interceptor(DevMailInterceptor)
566
- CODE
567
- end
568
- end
569
- end
570
- end
571
-
572
- desc 'config_env', 'Add code to environment files. Host refers to url options. Name option referes to controller and mailer default_url_options'
573
- option :name, required: true
574
- def config_env
575
- ENVIRONMENTS.each do |environment|
576
- case environment
577
- when 'development'
578
- inject_into_file 'config/environments/development.rb', after: "config.action_mailer.raise_delivery_errors = false\n" do <<-CODE
579
- config.action_mailer.delivery_method = :letter_opener
580
- config.action_mailer.perform_deliveries = false
581
- config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
582
- config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
583
- CODE
584
- end
585
- when 'test'
586
- inject_into_file 'config/environments/test.rb', after: "config.action_mailer.delivery_method = :test\n" do <<-CODE
587
- config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
588
- config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
589
- CODE
590
- end
591
- when 'production'
592
- inject_into_file 'config/environments/production.rb', after: "config.active_record.dump_schema_after_migration = false\n" do <<-CODE
593
- config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
594
- config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
595
- config.assets.compile = true
596
- CODE
597
- end
598
- end
599
- end
600
- end
601
-
602
- desc 'mysql_switch', 'Switch to mysql database'
603
- def mysql_switch
604
- gsub_file 'Gemfile', "gem 'sqlite3'", "gem 'mysql2', '>= 0.3.13', '< 0.5'"
605
- run 'bundle install'
606
- copy_file 'db/mysql_database.yml', 'config/database.yml'
607
- end
608
-
609
- desc 'new_ui NAME', 'Create a new ui view'
610
- def new_ui(name)
611
- run "touch app/views/ui/#{name}.html.haml"
612
- say "DON'T FORGET: Restart Powify App"
613
- end
614
-
615
- desc 'engine(full | mountable)', 'Generate a full or mountable engine. default: mountable'
616
- option :name, required: true
617
- def engine(etype='mountable')
618
- run "rails plugin new #{options[:name]} --dummy-path=spec/dummy --skip-test-unit --#{etype}"
619
- end
620
-
621
- desc 'engine_setup', 'Configure rails engine for development with RSpec, Capybara and FactoryBot'
622
- option :name, required: true
623
- def engine_setup
624
- gsub_file "#{options[:name]}.gemspec", 's.homepage = "TODO"', 's.homepage = "http://TBD.com"'
625
-
626
- gsub_file "#{options[:name]}.gemspec", "s.summary = \"TODO: Summary of #{options[:name].camelize}.\"", "s.summary = \"Summary of #{options[:name].camelize}.\""
627
-
628
- gsub_file "#{options[:name]}.gemspec", "s.description = \"TODO: Description of #{options[:name].camelize}.\"", "s.description = \"Description of #{options[:name].camelize}.\""
629
-
630
- inject_into_file "#{options[:name]}.gemspec", after: "s.license = \"MIT\"\n" do <<-CODE
631
- s.test_files = Dir["spec/**/*"]
632
- CODE
633
- end
634
-
635
- inject_into_file "#{options[:name]}.gemspec", after: "s.add_development_dependency \"sqlite3\"\n" do <<-CODE
636
- s.add_development_dependency 'rspec-rails'
637
- s.add_development_dependency 'capybara'
638
- s.add_development_dependency 'factory_bot_rails'
639
- s.add_development_dependency "faker"
640
- s.add_development_dependency "byebug"
641
- s.add_development_dependency 'rails-controller-testing'
642
- s.add_development_dependency 'pundit-matchers'
643
- s.add_development_dependency "simplecov"
644
- s.add_development_dependency "shoulda-matchers"
645
- s.add_development_dependency "database_cleaner"
646
- s.add_dependency 'pundit'
647
- s.add_dependency 'bootstrap-sass', '~> 3.3.6'
648
- s.add_dependency 'autoprefixer-rails'
649
- s.add_dependency "haml-rails"
650
- s.add_dependency "font-awesome-rails"
651
- s.add_dependency 'record_tag_helper'
652
- CODE
653
- end
654
-
655
- run 'bundle'
656
-
657
- Dir["#{__dir__}/myrails/templates/spec/**/*"].each do |file|
658
- if file.include? '/support/'
659
- copy_file file, "#{file.gsub(__dir__+'/myrails/templates/', '')}" unless File.directory? file
660
- end
661
- end
662
-
663
- copy_file 'engines/rakefile', 'Rakefile'
664
-
665
- run 'rails g rspec:install'
666
-
667
- gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }"
668
-
669
- gsub_file 'spec/rails_helper.rb', "require File.expand_path('../../config/environment', __FILE__)", "require_relative 'dummy/config/environment'"
670
-
671
- inject_into_file 'spec/rails_helper.rb', after: "require 'rspec/rails'\n" do <<-CODE
672
- require 'shoulda/matchers'
673
- require 'factory_bot'
674
- require 'database_cleaner'
675
- CODE
676
- end
677
-
678
- inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
679
- config.mock_with :rspec
680
- config.infer_base_class_for_anonymous_controllers = false
681
- config.order = "random"
682
- CODE
683
- end
684
-
685
- inject_into_file "lib/#{options[:name]}/engine.rb", after: "class Engine < ::Rails::Engine\n" do <<-CODE
686
- config.generators do |g|
687
- g.test_framework :rspec, :fixture => false
688
- g.fixture_replacement :factory_bot, :dir => 'spec/factories'
689
- g.assets false
690
- g.helper false
691
- end
692
- CODE
693
- end
694
- end
695
-
696
- desc 'shared_example', 'Generates an RSpec shared example template in the support directory'
697
- option :text, required: true
698
- def shared_example
699
- template 'spec/shared_example.rb', 'spec/support/shared_examples/shared_examples.rb'
700
- end
701
-
702
- desc 'request', 'Generates an RSpec request spec'
703
- option :name, required: true
704
- def request
705
- template 'spec/request.rb', "spec/requests/#{options[:name]}_spec.rb"
706
- copy_file 'spec/request_shared_example.rb', 'spec/support/shared_examples/request_shared_examples.rb'
707
- end
708
-
709
- desc 'feature', 'Generates an RSpec feature spec'
710
- option :name, required: true
711
- def feature
712
- copy_file 'spec/feature.rb', "spec/features/#{options[:name]}_spec.rb"
713
- end
714
-
715
- desc 'helper', 'Generates an RSpec helper in support/helpers for extracting reusable code'
716
- long_desc <<-LONGDESC
717
- `myrails helper` will generate an RSpec helper module to use with rspec.
718
-
719
- You can optionally specify a type parameter which will only include the module for the given type of spec.
720
-
721
- > $ myrails helper --name article --type :feature
722
- LONGDESC
723
- option :name, required: true
724
- option :type
725
- def helper
726
- template 'spec/helper.rb', "spec/support/helpers/#{options[:name].downcase.gsub("\s", '_')}.rb"
727
- insert_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
728
- config.include #{options[:name].camelize.gsub("\s", '')}Helper#{", type: #{options[:type]}" if options[:type]}
729
- CODE
730
- end
731
- end
732
-
733
- desc 'install NAME', 'Install customizations to convfigure application quickly. Type `myrails install` for options'
99
+ desc 'install NAME', 'Install customizations to configure application quickly. Type `myrails install` for options'
734
100
  def install(name=nil)
735
101
  options = {
736
102
  application_helper: 'Overwrite default application helper with a custom helper',
@@ -790,10 +156,11 @@ CODE
790
156
  when 'env_config'
791
157
  config_env
792
158
  else
793
- say "Unknown Action!"
159
+ say "Unknown Action! #{name}"
794
160
  end
795
161
  end
796
162
 
163
+
797
164
  end
798
165
  end
799
166