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
@@ -2,63 +2,93 @@ module Install
|
|
2
2
|
module RSpec
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
6
|
-
desc '
|
7
|
-
def
|
5
|
+
|
6
|
+
desc 'add_rspec_gem', 'Add RSpec gem to Gemfile and run bundler'
|
7
|
+
def add_rspec_gem
|
8
8
|
insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
|
9
|
-
|
10
|
-
|
11
|
-
CODE
|
9
|
+
gem 'rspec-rails', group: :test
|
10
|
+
CODE
|
12
11
|
end
|
13
12
|
|
14
13
|
run 'bundle install'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'generate_rspec', 'Run RSpec generator'
|
17
|
+
def generate_rspec
|
15
18
|
run 'rails g rspec:install'
|
16
|
-
|
17
|
-
install_rails_helper
|
18
|
-
|
19
|
-
Dir["#{__dir__}/../templates/spec/**/*"].each do |file|
|
20
|
-
if file.include?('/support/') && !['devise'].include?(File.basename(file, '.rb'))
|
21
|
-
copy_file file, "#{file.gsub(__dir__+'/../templates/', '')}" unless File.directory? file
|
22
|
-
end
|
23
|
-
end
|
24
19
|
end
|
25
|
-
|
26
|
-
desc '
|
27
|
-
def
|
20
|
+
|
21
|
+
desc 'setup_rspec_defaults', 'add default entris to spec/rails_helper.rb'
|
22
|
+
def setup_simplecov_capybara
|
28
23
|
inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
|
29
|
-
|
30
|
-
|
24
|
+
require 'simplecov'
|
25
|
+
SimpleCov.start
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
Capybara.app_host = "http://localhost:3000"
|
28
|
+
Capybara.server_host = "localhost"
|
29
|
+
Capybara.server_port = "3000"
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
31
|
+
#use Chromedriver
|
32
|
+
unless ENV['NOCHROME']
|
33
|
+
Capybara.register_driver :selenium do |app|
|
34
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome)
|
41
35
|
end
|
42
|
-
|
36
|
+
end
|
37
|
+
CODE
|
43
38
|
end
|
44
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'enable_support', 'Enable support files'
|
42
|
+
def enable_support
|
45
43
|
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 }"
|
46
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'disable_transctional_fixtures', 'Turn off transactional fixtures option'
|
47
|
+
def disable_transctional_fixtures
|
47
48
|
gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
|
48
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
desc 'include_modules', 'Include useful modules used in feature specs'
|
53
|
+
def include_modules
|
49
54
|
inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
# Can use methods like dom_id in features
|
56
|
+
config.include ActionView::RecordIdentifier, type: :feature
|
57
|
+
# Can use methods likke strip_tags in features
|
58
|
+
config.include ActionView::Helpers::SanitizeHelper, type: :feature
|
59
|
+
# Can use methods like truncate
|
60
|
+
config.include ActionView::Helpers::TextHelper, type: :feature
|
61
|
+
config.include(JavascriptHelper, type: :feature)
|
62
|
+
config.include MailerHelper
|
63
|
+
CODE
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
67
|
+
desc 'install_rails_helper', 'Add code to rspec/rails_helper so rspec runs the way I like'
|
68
|
+
def setup_rails_helper
|
69
|
+
setup_simplecov_capybara
|
70
|
+
enable_support
|
71
|
+
disable_transctional_fixtures
|
72
|
+
include_modules
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'setup_support_files', 'Generate RSpecsupport files'
|
76
|
+
def setup_support_files
|
77
|
+
Dir["#{__dir__}/../templates/spec/**/*"].each do |file|
|
78
|
+
if file.include?('/support/') && !['devise'].include?(File.basename(file, '.rb'))
|
79
|
+
copy_file file, "#{file.gsub(__dir__+'/../templates/', '')}" unless File.directory? file
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'setup_rspec', 'Generate rspec structure & rspec configuration that I commonly use'
|
85
|
+
def setup_rspec
|
86
|
+
add_rspec_gem
|
87
|
+
generate_rspec
|
88
|
+
setup_rails_helper
|
89
|
+
setup_support_files
|
90
|
+
end
|
91
|
+
|
62
92
|
end
|
63
93
|
end
|
64
94
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Generator
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
|
6
|
+
def self.included(thor)
|
7
|
+
|
8
|
+
thor.class_eval do
|
9
|
+
|
10
|
+
desc 'shared_example', 'Generates an RSpec shared example template in the support directory'
|
11
|
+
def shared_example
|
12
|
+
@description = ask "What is the NAME of shared example?, Ex: requires authorization. Default: ", :yellow, default: 'shared example'
|
13
|
+
@context = ask "What is the CONTEXT of the shared example?, Ex: authorized user. Default: ", :yellow, default: 'shared example'
|
14
|
+
|
15
|
+
template 'spec/shared_example.rb', "spec/support/shared_examples/#{@param.downcase.gsub("\s", '_')}_shared_examples.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'request', 'Generates an RSpec request spec'
|
19
|
+
def request
|
20
|
+
template 'spec/request.rb', "spec/requests/#{@param.downcase.gsub("\s", "_")}_spec.rb"
|
21
|
+
copy_file 'spec/request_shared_example.rb', 'spec/support/shared_examples/request_shared_examples.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'feature', 'Generates an RSpec feature spec'
|
25
|
+
def feature
|
26
|
+
@description = ask "What is the description of feature?, Ex: user management. Default: ", :yellow, default: 'feature'
|
27
|
+
@scenario = ask "What is the CONTEXT of the shared example?, Ex: as a user ... Default: ", :yellow, default: 'scneario'
|
28
|
+
|
29
|
+
template 'spec/feature.rb', "spec/features/#{@param.downcase.gsub("\s", '_')}_spec.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'helper', 'Generates an RSpec helper in support/helpers for extracting reusable code'
|
33
|
+
long_desc <<-LONGDESC
|
34
|
+
`myrails helper` will generate an RSpec helper module to use with rspec.
|
35
|
+
|
36
|
+
You can optionally specify a type parameter which will only include the module for the given type of spec.
|
37
|
+
|
38
|
+
> $ myrails helper --name article --type :feature
|
39
|
+
LONGDESC
|
40
|
+
|
41
|
+
def helper
|
42
|
+
@type = ask 'What is the type? Ex: :feature, :controller, :request, :model. Deafult: ', :yellow, default: :feature
|
43
|
+
template 'spec/helper.rb', "spec/support/helpers/#{@param.downcase.gsub("\s", '_')}.rb"
|
44
|
+
insert_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
|
45
|
+
config.include #{@param.camelize.gsub("\s", '')}Helper#{", type: #{':' unless @type.include?(':')}#{@type}" if @type}
|
46
|
+
CODE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -2,44 +2,45 @@ module RSpec
|
|
2
2
|
module Generators
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
6
|
-
desc '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
config.include #{options[:name].camelize.gsub("\s", '')}Helper#{", type: #{options[:type]}" if options[:type]}
|
39
|
-
CODE
|
5
|
+
|
6
|
+
desc 'spec <OPTION> <NAME>', 'Execute without options to see HELP. Generate a rspec template with a given name'
|
7
|
+
def spec(*opts)
|
8
|
+
item, @param = opts
|
9
|
+
|
10
|
+
option = {
|
11
|
+
example: 'Generate RSpec shared example temlate. Prompts for name and context',
|
12
|
+
feature: 'Generate RSpec feature template',
|
13
|
+
helper: 'Generates an RSpec helper in support/helpers for extracting reusable code',
|
14
|
+
request: 'Generate RSpec request template'
|
15
|
+
}
|
16
|
+
|
17
|
+
unless item
|
18
|
+
say 'ERROR: "myrails spec" was called with no arguments'
|
19
|
+
say 'Usage: "myrails spec <OPTION> <NAME>"'
|
20
|
+
say "Available Options:\n"
|
21
|
+
option.each{|k,v| say "* #{k}: #{v}"}
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
raise ArgumentError, "NAME must be specified for #{item} option. Ex: `myrails spec <OPTION> <NAME>`" unless @param
|
26
|
+
|
27
|
+
case item
|
28
|
+
when 'example'
|
29
|
+
shared_example
|
30
|
+
when 'feature'
|
31
|
+
feature
|
32
|
+
when 'helper'
|
33
|
+
helper
|
34
|
+
when 'request'
|
35
|
+
request
|
36
|
+
else
|
37
|
+
say "Unknown Action! #{@param}"
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
41
|
+
desc 's', 'spec shortcut'
|
42
|
+
alias_method :s, :spec
|
43
|
+
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
data/lib/myrails/modules/ui.rb
CHANGED
@@ -2,18 +2,35 @@ module Install
|
|
2
2
|
module Ui
|
3
3
|
def self.included(thor)
|
4
4
|
thor.class_eval do
|
5
|
-
|
5
|
+
|
6
|
+
desc 'generate_ui_controller', 'Generate the ui controller'
|
7
|
+
def generate_ui_controller
|
6
8
|
copy_file 'ui/ui_controller.rb', 'app/controllers/ui_controller.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'generate_index', 'Generate index view'
|
12
|
+
def generate_index
|
7
13
|
copy_file 'ui/index.html.haml', 'app/views/ui/index.html.haml'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'setup_route', 'Add route code to routes config'
|
17
|
+
def setup_route
|
8
18
|
inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-CODE
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
19
|
+
# Requires an application restart everytime a new page is added.
|
20
|
+
Dir.glob('app/views/ui/*.html.haml').sort.each do |file|
|
21
|
+
action = File.basename(file,'.html.haml')
|
22
|
+
get \"ui/\#{action}\", controller: 'ui', action: action
|
23
|
+
end
|
24
|
+
CODE
|
15
25
|
end
|
16
26
|
end
|
27
|
+
|
28
|
+
desc 'setup_ui', 'Generate UI route, controller and view setup'
|
29
|
+
def setup_ui
|
30
|
+
generate_ui_controller
|
31
|
+
generate_index
|
32
|
+
setup_route
|
33
|
+
end
|
17
34
|
|
18
35
|
end
|
19
36
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class <%=
|
2
|
-
# before_action :<%=
|
1
|
+
class <%= @name.pluralize.camelize %>Controller < <% if @name.include?("/")%><%= @name.split("/").first.camelize %>::<%= @name.split("/").first.camelize %><% else %>Application<% end %>Controller
|
2
|
+
# before_action :<%= @name.split("/").last.singularize %>, only: []
|
3
3
|
private
|
4
4
|
|
5
|
-
def <%=
|
6
|
-
@<%=
|
5
|
+
def <%= @name.split("/").last.singularize %>
|
6
|
+
@<%= @name.split("/").last.singularize %> = <%= @name.camelize.singularize %>.find(params[:id])
|
7
7
|
end
|
8
8
|
|
9
|
-
def <%=
|
10
|
-
params.require(:<%=
|
9
|
+
def <%= @name.split("/").last.singularize %>_params
|
10
|
+
params.require(:<%= @name.split("/").last.singularize %>).permit()
|
11
11
|
end
|
12
12
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= @name.split("/").first.camelize %>::<%= @name.split("/").first.camelize %>Controller < ApplicationController
|
2
2
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ApplicationDecorator < Draper::Decorator
|
2
|
+
delegate_all
|
3
|
+
include Draper::LazyHelpers
|
4
|
+
# Define methods for all decorated objects.
|
5
|
+
# Helpers are accessed through `helpers` (aka `h`). For example:
|
6
|
+
#
|
7
|
+
# def percent_amount
|
8
|
+
# h.number_to_percentage object.amount, precision: 2
|
9
|
+
# end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= @name.camelize %>Decorator < ApplicationDecorator
|
2
|
+
#decorates Namespaced::Model
|
3
|
+
|
4
|
+
# Return concatenated full name
|
5
|
+
def name
|
6
|
+
<%= @name %>.attribute + " " + <%= @name %>.attribute
|
7
|
+
end
|
8
|
+
|
9
|
+
# Return edit path
|
10
|
+
def edit_link
|
11
|
+
link_to :Edit, edit_<%= @name%>_path(<%= @name %>)
|
12
|
+
end
|
13
|
+
end
|
@@ -39,11 +39,4 @@ module ApplicationHelper
|
|
39
39
|
def us_date(date)
|
40
40
|
date.strftime("%m/%d/%Y at %H:%M %p") rescue 'unknown'
|
41
41
|
end
|
42
|
-
|
43
|
-
def present(object, klass = nil)
|
44
|
-
klass ||= "#{object.class}Presenter".constantize
|
45
|
-
presenter = klass.new(object, self)
|
46
|
-
yield presenter if block_given?
|
47
|
-
presenter
|
48
|
-
end
|
49
42
|
end
|
@@ -8,7 +8,7 @@ class DevMailInterceptor
|
|
8
8
|
dev_text += "BCC address is: #{message.bcc.to_a.join(", ")}\n"
|
9
9
|
|
10
10
|
message.subject = "[#{Socket.gethostname}] [#{Rails.env}] #{message.subject}"
|
11
|
-
message.to = '<%=
|
11
|
+
message.to = '<%= @email %>'
|
12
12
|
message.cc = ""
|
13
13
|
message.bcc = ""
|
14
14
|
append_address_info(message, dev_text)
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= @name.camelize %> < ApplicationRecord
|
2
2
|
end
|
@@ -1,24 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Allow all users to access new <%= options[:name] %>
|
1
|
+
class <%= @name.camelize %>Policy < ApplicationPolicy
|
2
|
+
|
4
3
|
def new?
|
5
4
|
true
|
6
5
|
end
|
7
6
|
|
8
|
-
# Allows owner to edit <%= options[:name].camelize %>
|
9
7
|
def edit?
|
10
8
|
user == record.user
|
11
9
|
end
|
12
10
|
|
13
|
-
# Allows all users to create <%= options[:name].camelize %>
|
14
11
|
alias_method :create?, :new?
|
15
12
|
|
16
|
-
# Allows all users to view <%= options[:name].camelize %>
|
17
13
|
alias_method :show?, :new?
|
18
14
|
|
19
|
-
# Allows owner to update an <%= options[:name].camelize %>
|
20
15
|
alias_method :update?, :edit?
|
21
16
|
|
22
|
-
# Allows owner to remove an <%= options[:name].camelize %>
|
23
17
|
alias_method :destroy?, :edit?
|
24
18
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# Presenter class for object views
|
2
|
-
class <%=
|
2
|
+
class <%= @name.camelize %>Presenter < BasePresenter
|
3
3
|
# Reference initialized object_presenter as object
|
4
|
-
presents :<%=
|
4
|
+
presents :<%= @name%>
|
5
5
|
|
6
|
-
# delegate :attribute, to: :<%=
|
6
|
+
# delegate :attribute, to: :<%= @name %>, allow_nil: true
|
7
7
|
|
8
8
|
# Return concatenated full name
|
9
9
|
def name
|
10
|
-
<%=
|
10
|
+
<%= @name %>.attribute + " " + <%= @name %>.attribute
|
11
11
|
end
|
12
12
|
|
13
13
|
# Return edit path
|
14
14
|
def edit_link
|
15
|
-
link_to :Edit, edit_<%=
|
15
|
+
link_to :Edit, edit_<%= @name%>_path(<%= @name %>)
|
16
16
|
end
|
17
17
|
end
|