myrails 6.0.0 → 7.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 +4 -4
- data/README.md +48 -30
- data/lib/myrails.rb +46 -122
- data/lib/myrails/modules/application_generator_actions.rb +61 -0
- data/lib/myrails/modules/application_generators.rb +80 -0
- data/lib/myrails/modules/assets.rb +28 -2
- data/lib/myrails/modules/bootstrap.rb +16 -12
- data/lib/myrails/modules/capistrano.rb +11 -6
- data/lib/myrails/modules/database_generator.rb +33 -0
- data/lib/myrails/modules/database_generator_actions.rb +18 -0
- data/lib/myrails/modules/devise.rb +11 -5
- data/lib/myrails/modules/dotenv.rb +30 -6
- data/lib/myrails/modules/draper.rb +29 -0
- data/lib/myrails/modules/engine_generator_actions.rb +117 -0
- data/lib/myrails/modules/engine_generators.rb +66 -0
- data/lib/myrails/modules/figaro.rb +18 -2
- data/lib/myrails/modules/gems.rb +7 -2
- data/lib/myrails/modules/heroku.rb +28 -9
- data/lib/myrails/modules/material.rb +23 -13
- data/lib/myrails/modules/pundit.rb +30 -6
- data/lib/myrails/modules/rails_generator_actions.rb +110 -0
- data/lib/myrails/modules/rails_generators.rb +49 -95
- data/lib/myrails/modules/rspec.rb +70 -40
- data/lib/myrails/modules/rspec_generator_actions.rb +56 -0
- data/lib/myrails/modules/rspec_generators.rb +36 -35
- data/lib/myrails/modules/ui.rb +24 -7
- data/lib/myrails/templates/rails/app/assets/javascripts/application.js +0 -4
- data/lib/myrails/templates/rails/app/controllers/controller.rb +6 -6
- data/lib/myrails/templates/rails/app/controllers/namespace_controller.rb +1 -1
- data/lib/myrails/templates/rails/app/decorators/application_decorator.rb +10 -0
- data/lib/myrails/templates/rails/app/decorators/decoration.rb +13 -0
- data/lib/myrails/templates/rails/app/helpers/application_helper.rb +0 -7
- data/lib/myrails/templates/rails/app/mailers/dev_mail_interceptor.rb +1 -1
- data/lib/myrails/templates/rails/app/models/model.rb +1 -1
- data/lib/myrails/templates/rails/app/models/namespace_model.rb +2 -2
- data/lib/myrails/templates/rails/app/policies/pundit.rb +2 -8
- data/lib/myrails/templates/rails/app/presenters/presenter.rb +5 -5
- data/lib/myrails/templates/rails/app/presenters/presenter_spec.rb +4 -4
- data/lib/myrails/templates/rails/app/views/layout/material/footer.html.haml +24 -0
- data/lib/myrails/templates/rails/config/application.example.yml +23 -23
- data/lib/myrails/templates/rails/config/initializers/sendgrid.rb +10 -0
- data/lib/myrails/templates/spec/controller.rb +37 -37
- data/lib/myrails/templates/spec/decorator_spec.rb +16 -0
- data/lib/myrails/templates/spec/factory.rb +1 -1
- data/lib/myrails/templates/spec/feature.rb +2 -2
- data/lib/myrails/templates/spec/helper.rb +1 -1
- data/lib/myrails/templates/spec/model.rb +1 -1
- data/lib/myrails/templates/spec/pundit.rb +5 -4
- data/lib/myrails/templates/spec/request.rb +27 -27
- data/lib/myrails/templates/spec/shared_example.rb +2 -2
- data/lib/myrails/templates/{rails/app/presenters/presenter_config.rb → spec/support/configs/decorator_presenter.rb} +0 -0
- data/lib/myrails/templates/ui/ui_controller.rb +1 -1
- data/lib/myrails/version.rb +1 -1
- data/myrails.gemspec +3 -3
- metadata +24 -15
- data/lib/myrails/modules/application.rb +0 -13
- data/lib/myrails/modules/database.rb +0 -15
- data/lib/myrails/modules/engine.rb +0 -107
- data/lib/myrails/modules/footnotes.rb +0 -19
- data/lib/myrails/templates/rails/app/mailers/sendgrid.rb +0 -8
@@ -0,0 +1,66 @@
|
|
1
|
+
module Engine
|
2
|
+
module Generators
|
3
|
+
def self.included(thor)
|
4
|
+
thor.class_eval do
|
5
|
+
|
6
|
+
desc 'engine <OPTION> <NAME>', 'Execute without options to see HELP. Generate and configure a rails engine'
|
7
|
+
def engine(*opts)
|
8
|
+
item = opts[0]
|
9
|
+
|
10
|
+
file = Dir['*.gemspec'].first
|
11
|
+
|
12
|
+
@name = if file
|
13
|
+
File.basename(file, '.gemspec')
|
14
|
+
else
|
15
|
+
opts[1]
|
16
|
+
end
|
17
|
+
|
18
|
+
option = {
|
19
|
+
# base_install: 'Generate a new mountable rails engine with a set of gems and a rake and rspec default configuration',
|
20
|
+
auto_setup: 'Run all of the setup options listed',
|
21
|
+
engine_setup: 'Generate default configuration in Rails::Engine. Requires the name of the engine as the argument',
|
22
|
+
gemspec_setup: 'Setup gempsec file with default information',
|
23
|
+
new: 'Generate clean a full or mountable rails gem',
|
24
|
+
rake_setup: 'Setup rake to run rspec as the default test framework along with other configs',
|
25
|
+
rspec_setup: 'Configure RSpec to work with a rails engine'
|
26
|
+
}
|
27
|
+
|
28
|
+
unless item
|
29
|
+
say 'ERROR: "myrails engine" was called with no arguments'
|
30
|
+
say 'Usage: "myrails engine <OPTION> <NAME>"'
|
31
|
+
say "Available Options:\n"
|
32
|
+
option.each{|k,v| say "* #{k}: #{v}"}
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
raise ArgumentError, "NAME must be specified for #{item} option. Ex: `myrails engine <OPTION> <NAME>`" unless @name
|
37
|
+
|
38
|
+
case item
|
39
|
+
# when 'base_install'
|
40
|
+
# base_install
|
41
|
+
when 'auto_setup'
|
42
|
+
auto_setup
|
43
|
+
when 'engine_setup'
|
44
|
+
engine_setup
|
45
|
+
when 'gem_setup'
|
46
|
+
gem_setup
|
47
|
+
when 'gemspec_setup'
|
48
|
+
gemspec_setup
|
49
|
+
when 'new'
|
50
|
+
new_engine
|
51
|
+
when 'rake_setup'
|
52
|
+
rake_setup
|
53
|
+
when 'rspec_setup'
|
54
|
+
rspec_setup
|
55
|
+
else
|
56
|
+
say "Unknown Action! #{@name}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'e', 'Engine shortcut'
|
61
|
+
alias_method :e, :engine
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -2,17 +2,33 @@ module Install
|
|
2
2
|
module Figaro
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
desc 'add_figaro', 'Add Figaro gem to Gemfile and run bundler'
|
7
|
+
def add_figaro
|
7
8
|
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
8
9
|
gem "figaro"
|
9
10
|
CODE
|
10
11
|
end
|
11
12
|
|
12
13
|
run 'bundle install'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'generate_figaro', 'Run Figaro installer'
|
17
|
+
def generate_figaro
|
13
18
|
run 'bundle exec figaro install'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'generate_example', 'Create example application.yml file'
|
22
|
+
def generate_example
|
14
23
|
copy_file 'rails/config/application.example.yml', 'config/application.example.yml'
|
15
24
|
end
|
25
|
+
|
26
|
+
desc 'setup_figaro', 'Install and configure figaro gem'
|
27
|
+
def setup_figaro
|
28
|
+
add_figaro
|
29
|
+
generate_figaro
|
30
|
+
generate_example
|
31
|
+
end
|
16
32
|
|
17
33
|
end
|
18
34
|
end
|
data/lib/myrails/modules/gems.rb
CHANGED
@@ -2,7 +2,8 @@ module Install
|
|
2
2
|
module Gems
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
5
|
+
|
6
|
+
desc 'add_test_group', 'Add test group gems to Gemfile'
|
6
7
|
def add_test_group
|
7
8
|
insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
|
8
9
|
group :test do
|
@@ -18,6 +19,7 @@ CODE
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
22
|
+
desc 'add_development_test_gems', 'Add test and development group gems to Gemfile'
|
21
23
|
def add_development_test_gems
|
22
24
|
insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
|
23
25
|
gem 'faker'
|
@@ -28,6 +30,7 @@ CODE
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
33
|
+
desc 'add_rails_gems', 'Add commonly used gems to Gemfile'
|
31
34
|
def add_rails_gems
|
32
35
|
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
33
36
|
gem 'haml-rails'
|
@@ -41,6 +44,7 @@ CODE
|
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
47
|
+
desc 'add_private_section', 'Add private section to appliation controller'
|
44
48
|
def add_private_section
|
45
49
|
insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
|
46
50
|
private
|
@@ -48,7 +52,8 @@ CODE
|
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
|
-
|
55
|
+
desc 'setup_gems', 'Install development, test and prodution gems'
|
56
|
+
def setup_gems
|
52
57
|
add_test_group
|
53
58
|
add_development_test_gems
|
54
59
|
add_rails_gems
|
@@ -3,20 +3,39 @@ module Install
|
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
group :production
|
10
|
-
gem '
|
11
|
-
gem 'rails_12factor'
|
12
|
-
end
|
6
|
+
desc 'add_heroku_gems', 'Add gems for heroku to Gemfile'
|
7
|
+
def add_heroku_gems
|
8
|
+
insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
|
9
|
+
gem 'pg', group: :production
|
10
|
+
gem 'rails_12factor', group: :production
|
13
11
|
|
14
|
-
CODE
|
12
|
+
CODE
|
15
13
|
end
|
14
|
+
run 'bundle install'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'create_sqlite3_config', 'Generate SQLITE3 database config'
|
18
|
+
def create_sqlite3_config
|
16
19
|
copy_file 'db/sqlite3_database.yml', 'config/database.yml'
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'create_heroku_procfile', 'Generate a procfile for use with heroku'
|
23
|
+
def create_heroku_procfile
|
17
24
|
copy_file 'heroku/Procfile', 'Procfile'
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'create_heroku_puma_config', 'Generate a puma config for use with heroku'
|
28
|
+
def create_heroku_puma_config
|
18
29
|
copy_file 'heroku/puma.rb', 'config/puma.rb'
|
19
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'install_heroku', 'setup application for use with heroku using sqlite3 for development'
|
33
|
+
def setup_heroku
|
34
|
+
add_heroku_gems
|
35
|
+
create_sqlite3_config
|
36
|
+
create_heroku_procfile
|
37
|
+
create_heroku_puma_config
|
38
|
+
end
|
20
39
|
|
21
40
|
end
|
22
41
|
end
|
@@ -2,26 +2,27 @@ module Layout
|
|
2
2
|
module Material
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
6
|
-
|
5
|
+
desc 'generate_material_files', 'Generate material layout files'
|
6
|
+
def generate_material_files
|
7
|
+
Dir[File.join("#{__dir__}", "..", "templates", "rails", "app", "views", "layout", "material", "**", "*")].each do |file|
|
7
8
|
copy_file file, "app/views/layouts/#{File.basename(file)}"
|
8
9
|
end
|
9
10
|
end
|
10
|
-
|
11
|
-
desc '
|
12
|
-
def
|
13
|
-
@templates = "#{__dir__}/../templates"
|
11
|
+
|
12
|
+
desc 'add_material_gem', 'Add materialize sass and icons gem to Gemfile and run bundler'
|
13
|
+
def add_material_gem
|
14
14
|
|
15
15
|
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
gem 'materialize-sass'
|
17
|
+
gem 'material_icons'
|
18
|
+
CODE
|
19
19
|
end
|
20
20
|
|
21
21
|
run 'bundle install'
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'setup_application_sass', 'add materialize to sass manifest'
|
25
|
+
def setup_materialize_css
|
25
26
|
insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
|
26
27
|
@import "materialize/components/color"
|
27
28
|
$primary-color: color("grey", "darken-3") !default
|
@@ -30,12 +31,21 @@ $secondary-color: color("grey", "base") !default
|
|
30
31
|
@import material_icons
|
31
32
|
CODE
|
32
33
|
end
|
33
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'add_materialize_js', 'add materialize to js manifest'
|
37
|
+
def setup_materialize_js
|
34
38
|
insert_into_file 'app/assets/javascripts/application.js', before: "//= require trix" do <<-CODE
|
35
39
|
//= require materialize
|
36
40
|
CODE
|
37
41
|
end
|
38
42
|
end
|
43
|
+
desc 'install_material', 'Generate Material css theme'
|
44
|
+
def setup_material
|
45
|
+
generate_material_files
|
46
|
+
setup_materialize_css
|
47
|
+
setup_materialize_js
|
48
|
+
end
|
39
49
|
|
40
50
|
end
|
41
51
|
end
|
@@ -3,20 +3,36 @@ module Install
|
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
5
|
|
6
|
-
|
6
|
+
desc 'add_pundit_gem', 'Add Pundit gem to Gemfile'
|
7
|
+
def add_pundit_gem
|
7
8
|
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
8
9
|
gem 'pundit'
|
9
10
|
CODE
|
10
11
|
end
|
11
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
desc 'add_pundit_matcher_gem', 'Add Pundit Matcher gfem to Gemfile'
|
16
|
+
def add_pundit_matcher_gem
|
12
17
|
insert_into_file 'Gemfile', after: "group :test do\n" do <<-CODE
|
13
18
|
gem 'pundit-matchers'
|
14
19
|
CODE
|
15
20
|
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'add_pundit_gems', 'Add pundit and pundit-matches to Gemfile and run bundler'
|
24
|
+
def add_pundit_gems
|
25
|
+
add_pundit_gem
|
26
|
+
add_pundit_matcher_gem
|
16
27
|
run 'bundle update'
|
17
28
|
end
|
29
|
+
desc 'generate_pundit_files', 'Run pundit generator'
|
30
|
+
def generate_pundit_files
|
31
|
+
run 'rails g pundit:install'
|
32
|
+
end
|
18
33
|
|
19
|
-
|
34
|
+
desc 'include_pundit', 'Add Pundit to the application controller'
|
35
|
+
def include_pundit
|
20
36
|
inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-CODE
|
21
37
|
# Add pundit authorization
|
22
38
|
include Pundit
|
@@ -25,7 +41,10 @@ CODE
|
|
25
41
|
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
26
42
|
CODE
|
27
43
|
end
|
28
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'add_pundit_rescue_notice', 'Add notice to gracefully rescue from Pundit error'
|
47
|
+
def add_pundit_rescue_notice
|
29
48
|
inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
|
30
49
|
# Method to gracefully let a user know they are are not authorized
|
31
50
|
#
|
@@ -37,11 +56,16 @@ CODE
|
|
37
56
|
CODE
|
38
57
|
end
|
39
58
|
end
|
59
|
+
|
60
|
+
def enable_pundit
|
61
|
+
include_pundit
|
62
|
+
add_pundit_rescue_notice
|
63
|
+
end
|
40
64
|
|
41
65
|
desc 'install_pundit', 'Install pundit gem and generate pundit files and application controller code'
|
42
|
-
def
|
66
|
+
def setup_pundit
|
43
67
|
add_pundit_gems
|
44
|
-
|
68
|
+
generate_pundit_files
|
45
69
|
enable_pundit
|
46
70
|
end
|
47
71
|
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generator
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
ENVIRONMENTS = %w(development test production)
|
6
|
+
|
7
|
+
def self.included(thor)
|
8
|
+
|
9
|
+
thor.class_eval do
|
10
|
+
|
11
|
+
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"
|
12
|
+
def model
|
13
|
+
template 'rails/app/models/model.rb', "app/models/#{@name.downcase}.rb"
|
14
|
+
template 'rails/app/models/namespace_model.rb', "app/models/#{@name.split("/").first.singularize.downcase}.rb" if @name.include?("/")
|
15
|
+
template 'spec/model.rb', "spec/models/#{@name.downcase}_spec.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'controller', "Generates a rails controller with the given name along with related spec file. Use '/' to create a namespaced controller"
|
19
|
+
def controller
|
20
|
+
template 'rails/app/controllers/controller.rb', "app/controllers/#{@name.downcase.pluralize}_controller.rb"
|
21
|
+
if @name.include?("/")
|
22
|
+
parent, child = name.split("/")
|
23
|
+
template 'rails/app/controllers/namespace_controller.rb', "app/controllers/#{parent}/#{parent.downcase}_controller.rb"
|
24
|
+
end
|
25
|
+
|
26
|
+
template 'spec/controller.rb', "spec/controllers/#{@name.downcase.pluralize}_controller_spec.rb"
|
27
|
+
run "mkdir -p app/views/#{@name.downcase.pluralize}"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'policy', "Generates a pundit policy with the given name and a related spec file. Use '/' to create a namespaced policy"
|
31
|
+
def policy
|
32
|
+
template 'rails/app/policies/pundit.rb', "app/policies/#{@name.downcase}_policy.rb"
|
33
|
+
template 'spec/pundit.rb', "spec/policies/#{@name.downcase}_policy_spec.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'decorator', 'Generates draper decoration with given name and related spec file'
|
37
|
+
def decorator
|
38
|
+
copy_file 'rails/app/decorators/application_decorator.rb', 'app/decorators/application_decorator.rb'
|
39
|
+
template 'rails/app/decorators/decoration.rb', "app/decorators/#{@name.downcase}_decoration.rb"
|
40
|
+
copy_file 'spec/support/configs/decorator_presenter.rb', 'spec/support/configs/decorator_presenter.rb'
|
41
|
+
template 'spec/decorator_spec.rb', "spec/decorators/#{@name.downcase}_decorator_spec.rb"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'factory', "Generates a factory_bot factory in the spec/factories directory. Use '/' to create a namespaced factory"
|
45
|
+
def factory
|
46
|
+
template 'spec/factory.rb', "spec/factories/#{@name.downcase}.rb"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'config_env', 'Add code to environment files. Host refers to url options. Name option referes to controller and mailer default_url_options'
|
50
|
+
def config_env
|
51
|
+
ENVIRONMENTS.each do |environment|
|
52
|
+
case environment
|
53
|
+
when 'development'
|
54
|
+
inject_into_file 'config/environments/development.rb', after: "config.action_mailer.raise_delivery_errors = false\n" do <<-CODE
|
55
|
+
config.action_mailer.delivery_method = :letter_opener
|
56
|
+
config.action_mailer.perform_deliveries = false
|
57
|
+
config.action_mailer.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
58
|
+
config.action_controller.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
59
|
+
CODE
|
60
|
+
end
|
61
|
+
when 'test'
|
62
|
+
inject_into_file 'config/environments/test.rb', after: "config.action_mailer.delivery_method = :test\n" do <<-CODE
|
63
|
+
config.action_mailer.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
64
|
+
config.action_controller.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
65
|
+
CODE
|
66
|
+
end
|
67
|
+
when 'production'
|
68
|
+
inject_into_file 'config/environments/production.rb', after: "config.active_record.dump_schema_after_migration = false\n" do <<-CODE
|
69
|
+
config.action_mailer.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
70
|
+
config.action_controller.default_url_options = { host: ENV.fetch('DEFAULT_HOST') }
|
71
|
+
config.assets.compile = true
|
72
|
+
CODE
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
desc 'new_ui NAME', 'Create a new ui view'
|
79
|
+
def new_ui
|
80
|
+
run "touch app/views/ui/#{@name.downcase}.html.haml"
|
81
|
+
say "DON'T FORGET: Restart the rails app"
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
# desc 'presenter', "Generates a presenter class with the given name and a related spec file. Use '/' to create a namespaced presenter"
|
95
|
+
# option :name, required: true
|
96
|
+
# def presenters
|
97
|
+
# inject_into_file 'app/helpers/application_helper.rb', after: "module ApplicationHelper\n" do <<-CODE
|
98
|
+
# def present(object, klass = nil)
|
99
|
+
# klass ||= "#{object.class}Presenter".constantize
|
100
|
+
# presenter = klass.new(object, self)
|
101
|
+
# yield presenter if block_given?
|
102
|
+
# presenter
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# CODE
|
106
|
+
# copy_file 'rails/app/presenters/base.rb', 'app/presenters/base_presenter.rb'
|
107
|
+
# template 'rails/app/presenters/presenter.rb', "app/presenters/#{options[:name].downcase}_presenter.rb"
|
108
|
+
# copy_file 'spec/support/configs/decorator_presenter.rb', 'spec/support/configs/decorator_presenter.rb'
|
109
|
+
# template 'rails/app/presenters/presenter_spec.rb', "spec/presenters/#{options[:name].downcase}_presenter_spec.rb"
|
110
|
+
# end
|
@@ -1,102 +1,56 @@
|
|
1
1
|
module Rails
|
2
2
|
module Generators
|
3
|
+
# ENVIRONMENTS = %w(development test production)
|
4
|
+
|
3
5
|
def self.included(thor)
|
4
6
|
thor.class_eval do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
desc 'policy', "Generates a pundit policy with the given name and a related spec file. Use '/' to create a namespaced policy"
|
27
|
-
option :name, required: true
|
28
|
-
def policy
|
29
|
-
template 'rails/app/policies/pundit.rb', "app/policies/#{options[:name].downcase}_policy.rb"
|
30
|
-
template 'spec/pundit.rb', "spec/policies/#{options[:name].downcase}_policy_spec.rb"
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'presenter', "Generates a presenter class with the given name and a related spec file. Use '/' to create a namespaced presenter"
|
34
|
-
option :name, required: true
|
35
|
-
def presenters
|
36
|
-
copy_file 'rails/app/presenters/base.rb', 'app/presenters/base_presenter.rb'
|
37
|
-
template 'rails/app/presenters/presenter.rb', "app/presenters/#{options[:name].downcase}_presenter.rb"
|
38
|
-
copy_file 'rails/app/presenters/presenter_config.rb', 'spec/support/configs/presenter.rb'
|
39
|
-
template 'rails/app/presenters/presenter_spec.rb', "spec/presenters/#{options[:name].downcase}_presenter_spec.rb"
|
40
|
-
end
|
41
|
-
|
42
|
-
desc 'factory', "Generates a factory_bot factory in the spec/factories directory. Use '/' to create a namespaced factory"
|
43
|
-
option :name, required: true
|
44
|
-
def factory
|
45
|
-
template 'spec/factory.rb', "spec/factories/#{options[:name].downcase}.rb"
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'sendgrid', 'Generate sendgrid initializer and mail interceptor'
|
49
|
-
option :email, required: true
|
50
|
-
def sendgrid
|
51
|
-
copy_file 'rails/app/mailers/sendgrid.rb', 'config/initializers/sendgrid.rb'
|
52
|
-
template 'rails/app/mailers/dev_mail_interceptor.rb', 'app/mailers/dev_mail_interceptor.rb'
|
53
|
-
ENVIRONMENTS.each do |environment|
|
54
|
-
unless environment == 'production'
|
55
|
-
inject_into_file "config/environments/#{environment}.rb", after: "Rails.application.configure do\n" do <<-CODE
|
56
|
-
ActionMailer::Base.register_interceptor(DevMailInterceptor)
|
57
|
-
CODE
|
58
|
-
end
|
59
|
-
end
|
7
|
+
desc 'kickstart <OPTION> <NAME>', 'Execute without options to see HELP. Generate a rails template with a given name'
|
8
|
+
def kickstart(*opts)
|
9
|
+
item, @name = opts
|
10
|
+
|
11
|
+
option = {
|
12
|
+
controller: 'Generate rails controller with corresponding RSpec file',
|
13
|
+
decorator: 'Generate draper decorator with corresponding RSpec file',
|
14
|
+
factory: 'Generate factory[girl|bot] factory',
|
15
|
+
model: 'Generate rails model with corresponding RSpec file',
|
16
|
+
policy: 'Generate pundit policy with corresponding RSpec file',
|
17
|
+
ui: 'Generate a ui file for mocking front end'
|
18
|
+
}
|
19
|
+
|
20
|
+
unless item
|
21
|
+
say 'ERROR: "myrails kickstart" was called with no arguments'
|
22
|
+
say 'Usage: "myrails kickstart <OPTION> <NAME>"'
|
23
|
+
say "Available Options:\n"
|
24
|
+
option.each{|k,v| say "* #{k}: #{v}"}
|
25
|
+
exit
|
60
26
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
when 'production'
|
83
|
-
inject_into_file 'config/environments/production.rb', after: "config.active_record.dump_schema_after_migration = false\n" do <<-CODE
|
84
|
-
config.action_mailer.default_url_options = { host: ENV['DEFAULT_HOST'] }
|
85
|
-
config.action_controller.default_url_options = { host: ENV['DEFAULT_HOST'] }
|
86
|
-
config.assets.compile = true
|
87
|
-
CODE
|
88
|
-
end
|
89
|
-
end
|
27
|
+
|
28
|
+
raise ArgumentError, "NAME must be specified for #{item} option. Ex: `myrails kickstart <OPTION> <NAME>`" unless @name
|
29
|
+
|
30
|
+
case item
|
31
|
+
when 'model'
|
32
|
+
model
|
33
|
+
when 'controller'
|
34
|
+
controller
|
35
|
+
when 'policy'
|
36
|
+
policy
|
37
|
+
when 'ui'
|
38
|
+
new_ui
|
39
|
+
when 'policy'
|
40
|
+
policy
|
41
|
+
when 'decorator'
|
42
|
+
decorator
|
43
|
+
when 'factory'
|
44
|
+
factory
|
45
|
+
else
|
46
|
+
say "Unknown Action! #{@name}"
|
90
47
|
end
|
91
48
|
end
|
92
|
-
|
93
|
-
desc '
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
49
|
+
|
50
|
+
desc 'ks', 'Kickstart shortcut'
|
51
|
+
alias_method :ks, :kickstart
|
52
|
+
|
53
|
+
end # end thor.class_eval
|
54
|
+
end # end self.included
|
55
|
+
end # end module Generators
|
56
|
+
end # end module Rails
|