boring_generators 0.6.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +7 -1
  3. data/CHANGELOG.md +23 -0
  4. data/Gemfile.lock +65 -65
  5. data/README.md +20 -7
  6. data/Rakefile +1 -0
  7. data/lib/boring_generators/version.rb +1 -1
  8. data/lib/generators/boring/active_storage/aws/install/install_generator.rb +10 -8
  9. data/lib/generators/boring/active_storage/azure/install/install_generator.rb +9 -7
  10. data/lib/generators/boring/active_storage/google/install/install_generator.rb +9 -7
  11. data/lib/generators/boring/ahoy/install/install_generator.rb +31 -0
  12. data/lib/generators/boring/ahoy/install/templates/README +10 -0
  13. data/lib/generators/boring/audit/install/install_generator.rb +12 -9
  14. data/lib/generators/boring/bullet/install/install_generator.rb +4 -8
  15. data/lib/generators/boring/ci/github_action/install/install_generator.rb +1 -1
  16. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +15 -2
  17. data/lib/generators/boring/devise/install/install_generator.rb +1 -7
  18. data/lib/generators/boring/font_awesome/ruby_gem/install/install_generator.rb +3 -8
  19. data/lib/generators/boring/graphql/install/install_generator.rb +3 -7
  20. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  21. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +12 -67
  22. data/lib/generators/boring/oauth/facebook/install/templates/README +2 -3
  23. data/lib/generators/boring/oauth/github/install/install_generator.rb +36 -0
  24. data/lib/generators/boring/oauth/github/install/templates/README +23 -0
  25. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  26. data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
  27. data/lib/generators/boring/oauth/google/install/templates/README +23 -0
  28. data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
  29. data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
  30. data/lib/generators/boring/oauth/twitter/install/templates/README +23 -0
  31. data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
  32. data/lib/generators/boring/paper_trail/install/install_generator.rb +40 -0
  33. data/lib/generators/boring/payments/stripe/install/install_generator.rb +43 -0
  34. data/lib/generators/boring/payments/stripe/install/templates/README +21 -0
  35. data/lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb +63 -0
  36. data/lib/generators/boring/payments/stripe/install/templates/stripe.rb +1 -0
  37. data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/create.js.erb +13 -0
  38. data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/show.html.erb +8 -0
  39. data/lib/generators/boring/pry/install/install_generator.rb +4 -9
  40. data/lib/generators/boring/pundit/install/install_generator.rb +1 -7
  41. data/lib/generators/boring/rails_admin/install/install_generator.rb +36 -0
  42. data/lib/generators/boring/rubocop/install/install_generator.rb +3 -1
  43. data/lib/generators/boring/simple_form/install/install_generator.rb +4 -8
  44. data/lib/generators/boring/stimulus/install/install_generator.rb +24 -0
  45. data/lib/generators/boring/tailwind/install/install_generator.rb +11 -10
  46. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  47. data/lib/generators/boring/twilio/install/install_generator.rb +26 -0
  48. data/lib/generators/boring/twilio/install/templates/README +11 -0
  49. data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
  50. metadata +27 -2
@@ -10,14 +10,10 @@ module Boring
10
10
  desc: "Skips adding bullet development configuration"
11
11
 
12
12
  def add_bullet_gem
13
- say "Adding Bullet gem", :green
14
- bullet_gem_content = <<~RUBY
15
- \n
16
- \t# reports N+1 queries
17
- \tgem "bullet"
18
- RUBY
19
- insert_into_file "Gemfile", bullet_gem_content, after: /group :development do/
20
- run "bundle install"
13
+ say "Adding bullet gem", :green
14
+ Bundler.with_unbundled_env do
15
+ run "bundle add bullet --group development"
16
+ end
21
17
  end
22
18
 
23
19
  def add_bullet_gem_configuration
@@ -10,7 +10,7 @@ module Boring
10
10
  RUBY_VERSION_FILE = ".ruby-version"
11
11
 
12
12
  DEFAULT_RUBY_VERSION = ".ruby-version"
13
- DEFAULT_NODE_VERSION = "10.13.0"
13
+ DEFAULT_NODE_VERSION = "14"
14
14
  DEFAULT_REPOSITORY_NAME = "boring_generators"
15
15
 
16
16
  class_option :ruby_version, type: :string, aliases: "-v",
@@ -1,5 +1,9 @@
1
1
  name: CI
2
- on: [push]
2
+ on:
3
+ push:
4
+ branches: [ main ]
5
+ pull_request:
6
+ branches: [ main ]
3
7
  jobs:
4
8
  test:
5
9
  name: Tests
@@ -10,8 +14,9 @@ jobs:
10
14
  env:
11
15
  POSTGRES_USER: <%= @repository_name %>
12
16
  POSTGRES_DB: <%= "#{@repository_name}_test" %>
13
- POSTGRES_PASSWORD: ""
17
+ POSTGRES_PASSWORD: postgres
14
18
  ports: ["5432:5432"]
19
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
15
20
 
16
21
  steps:
17
22
  - name: Checkout code
@@ -25,6 +30,8 @@ jobs:
25
30
  uses: actions/setup-node@v1
26
31
  with:
27
32
  node-version: <%= @node_version %>
33
+ - name: Install library for postgres
34
+ run: sudo apt-get install libpq-dev
28
35
  - name: Find yarn cache location
29
36
  id: yarn-cache
30
37
  run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -43,7 +50,13 @@ jobs:
43
50
  RAILS_ENV: test
44
51
  PGHOST: localhost
45
52
  PGUSER: <%= @repository_name %>
53
+ PGPASSWORD: postgres
46
54
  run: |
47
55
  bin/rails db:setup
48
56
  - name: Run tests
57
+ env:
58
+ RAILS_ENV: test
59
+ PGHOST: localhost
60
+ PGUSER: <%= @repository_name %>
61
+ PGPASSWORD: postgres
49
62
  run: bundle exec rails test # TODO: Update the test runner command as per your requirement.
@@ -16,14 +16,8 @@ module Boring
16
16
 
17
17
  def add_devise_gem
18
18
  say "Adding devise gem", :green
19
- devise_gem = <<~RUBY
20
- \n
21
- # for authentication
22
- gem 'devise', '~> 4.7'
23
- RUBY
24
- append_to_file "Gemfile", devise_gem
25
19
  Bundler.with_unbundled_env do
26
- run "bundle install"
20
+ run "bundle add devise"
27
21
  end
28
22
  end
29
23
 
@@ -8,14 +8,9 @@ module Boring
8
8
 
9
9
  def add_font_awesome_sass_gem
10
10
  say "Adding font_awesome_sass gem", :green
11
-
12
- font_awesome_sass_gem = <<~RUBY
13
- \n
14
- # for adding font-awesome icons
15
- gem 'font-awesome-sass', '~> 5.13'
16
- RUBY
17
- append_to_file "Gemfile", font_awesome_sass_gem
18
- run "bundle install"
11
+ Bundler.with_unbundled_env do
12
+ run "bundle add font-awesome-sass"
13
+ end
19
14
  end
20
15
 
21
16
  def import_font_awesome_stylesheet
@@ -13,13 +13,9 @@ module Boring
13
13
 
14
14
  def add_graphql_gem
15
15
  say "Adding graphql gem", :green
16
- graphql_gem = <<~RUBY
17
- \n
18
- # for building APIs
19
- gem 'graphql', '~> 1.11'
20
- RUBY
21
- append_to_file "Gemfile", graphql_gem
22
- run "bundle install"
16
+ Bundler.with_unbundled_env do
17
+ run "bundle add graphql"
18
+ end
23
19
  end
24
20
 
25
21
  def run_graphql_generator
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+
5
+ module Boring
6
+ module Oauth
7
+ module BaseGenerator
8
+ def add_provider_and_uuid_user_details
9
+ say "Adding migration to add provider and uuid columns to users", :green
10
+ Bundler.with_unbundled_env do
11
+ run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string"
12
+ end
13
+ end
14
+
15
+ def configure_devise_omniauth
16
+ say "Adding omniauth devise configuration", :green
17
+ if File.exist?("config/initializers/devise.rb")
18
+ insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/
19
+ \n
20
+ \tconfig.omniauth :#{@oauth_name}, "APP_ID", "APP_SECRET"
21
+ RUBY
22
+ else
23
+ raise MissingDeviseConfigurationError, <<~ERROR
24
+ Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers.
25
+ ERROR
26
+ end
27
+ end
28
+
29
+ def add_omniauth_callback_routes
30
+ devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup
31
+ route devise_route
32
+ end
33
+
34
+ def add_omniauth_callback_controller
35
+ say "Copying omniauth_callbacks_controller.rb", :green
36
+ template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb")
37
+ end
38
+
39
+ def configure_and_add_devise_setting_in_user_model
40
+ say "Configuring #{@oauth_name.to_s} omniauth for user model", :green
41
+ insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/
42
+ \n\tdevise :omniauthable, omniauth_providers: %i[#{@oauth_name}]
43
+
44
+ \tdef self.from_omniauth(auth)
45
+ \twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user|
46
+ \tuser.email = auth.info.email
47
+ \tuser.password = Devise.friendly_token[0, 20]
48
+ \t# user.name = auth.info.name # assuming the user model has a name
49
+ \t# user.image = auth.info.image # assuming the user model has an image
50
+ \t# If you are using confirmable and the provider(s) you use validate emails,
51
+ \t# uncomment the line below to skip the confirmation emails.
52
+ \t# user.skip_confirmation!
53
+ \tend
54
+ \tend
55
+ RUBY
56
+ end
57
+
58
+ def show_readme
59
+ readme "README"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
4
5
 
5
6
  module Boring
6
7
  module Oauth
7
8
  module Facebook
8
9
  class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
9
12
  class MissingDeviseConfigurationError < StandardError; end
10
13
 
11
14
  desc "Adds facebook OmniAuth to the application"
@@ -13,77 +16,19 @@ module Boring
13
16
 
14
17
  def add_facebook_omniauth_gem
15
18
  say "Adding Facebook OmniAuth gem", :green
16
- facebook_omniauth_gem = <<~RUBY
17
- \n
18
- # for omniauth facebook
19
- gem 'omniauth-facebook', '~> 8.0'
20
- RUBY
21
- append_to_file "Gemfile", facebook_omniauth_gem
22
- Bundler.with_unbundled_env do
23
- run "bundle install"
24
- end
25
- end
26
-
27
- def add_provider_and_uuid_user_details
28
- say "Adding migration to add provider and uuid columns to users", :green
29
19
  Bundler.with_unbundled_env do
30
- run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string"
20
+ run "bundle add omniauth-facebook"
31
21
  end
32
22
  end
33
23
 
34
- def configure_devise_omniauth_facebook
35
- say "Adding omniauth devise configuration", :green
36
- if File.exist?("config/initializers/devise.rb")
37
- insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/
38
- \n
39
- \tconfig.omniauth :facebook, "APP_ID", "APP_SECRET"
40
- RUBY
41
- else
42
- raise MissingDeviseConfigurationError, <<~ERROR
43
- Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers.
44
- ERROR
45
- end
46
- end
47
-
48
- def add_omniauth_callback_routes
49
- devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup
50
- route devise_route
51
- end
52
-
53
- def add_omniauth_callback_controller
54
- say "Copying omniauth_callbacks_controller.rb", :green
55
- template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb")
56
- end
57
-
58
- def configure_and_add_devise_setting_in_user_model
59
- say "Configuring facebook omniauth for user model", :green
60
- insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/
61
-
62
- \tdevise :omniauthable, omniauth_providers: %i[facebook]
63
-
64
- \tdef self.from_omniauth(auth)
65
- \twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user|
66
- \tuser.email = auth.info.email
67
- \tuser.password = Devise.friendly_token[0, 20]
68
- \tuser.name = auth.info.name # assuming the user model has a name
69
- \t# user.image = auth.info.image # assuming the user model has an image
70
- \t# If you are using confirmable and the provider(s) you use validate emails,
71
- \t# uncomment the line below to skip the confirmation emails.
72
- \t# user.skip_confirmation!
73
- \tend
74
- \tend
75
- RUBY
76
- end
77
-
78
- def add_the_facebook_devise_omniauth_view
79
- insert_into_file "app/views/users/sessions/new.html.erb", <<~RUBY, after: /<%= render "users\/shared\/links" %>/
80
-
81
- <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
82
- RUBY
83
- end
84
-
85
- def show_readme
86
- readme "README"
24
+ def invoke_common_generator_methods
25
+ @oauth_name = :facebook
26
+ add_provider_and_uuid_user_details
27
+ configure_devise_omniauth
28
+ add_omniauth_callback_routes
29
+ add_omniauth_callback_controller
30
+ configure_and_add_devise_setting_in_user_model
31
+ show_readme
87
32
  end
88
33
  end
89
34
  end
@@ -16,9 +16,8 @@ Some setup you must do manually if you haven't yet:
16
16
  For example:
17
17
 
18
18
  config.omniauth :facebook, "APP_ID", "APP_SECRET"
19
- 3. Ensure you have added the facebook omniauth route in the devise session view:
20
- For example:
21
19
 
22
- <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
20
+ 3. Your omniauth callback URL will be: `<host>/users/auth/facebook/callback`. Please update
21
+ callback URL in Facebook after registering your omniauth application.
23
22
 
24
23
  ===============================================================================
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Github
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds GitHub OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_github_omniauth_gem
18
+ say "Adding GitHub OmniAuth gem", :green
19
+ Bundler.with_unbundled_env do
20
+ run "bundle add omniauth-github"
21
+ end
22
+ end
23
+
24
+ def invoke_common_generator_methods
25
+ @oauth_name = :github
26
+ add_provider_and_uuid_user_details
27
+ configure_devise_omniauth
28
+ add_omniauth_callback_routes
29
+ add_omniauth_callback_controller
30
+ configure_and_add_devise_setting_in_user_model
31
+ show_readme
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
6
+ For example:
7
+
8
+ Rails.application.routes.draw do
9
+ devise_for :users, controllers: {
10
+ omniauth_callbacks: "users/omniauth_callbacks"
11
+ }
12
+ end
13
+
14
+ 2. Update the devise github omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://github.com/settings/applications/new
16
+ For example:
17
+
18
+ config.omniauth :github, "APP_ID", "APP_SECRET"
19
+
20
+ 3. Your omniauth callback URL will be: `<host>/users/auth/github/callback`. Please update
21
+ callback URL in Github after registering your omniauth application.
22
+
23
+ ===============================================================================
@@ -0,0 +1,21 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
3
+ skip_before_action :verify_authenticity_token, only: :github
4
+
5
+ def github
6
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
7
+ @user = User.from_omniauth(request.env["omniauth.auth"])
8
+
9
+ if @user.persisted?
10
+ sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
11
+ set_flash_message(:notice, :success, kind: "GitHub") if is_navigational_format?
12
+ else
13
+ session["devise.github_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
14
+ redirect_to new_user_registration_url
15
+ end
16
+ end
17
+
18
+ def failure
19
+ redirect_to root_path
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'generators/boring/oauth/base_generator'
5
+
6
+ module Boring
7
+ module Oauth
8
+ module Google
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Boring::Oauth::BaseGenerator
11
+
12
+ class MissingDeviseConfigurationError < StandardError; end
13
+
14
+ desc "Adds Google OmniAuth to the application"
15
+ source_root File.expand_path("templates", __dir__)
16
+
17
+ def add_github_omniauth_gem
18
+ say "Adding GitHub OmniAuth gem", :green
19
+ Bundler.with_unbundled_env do
20
+ run "bundle add omniauth-google-oauth2"
21
+ end
22
+ end
23
+
24
+ def invoke_common_generator_methods
25
+ @oauth_name = :google_oauth2
26
+ add_provider_and_uuid_user_details
27
+ configure_devise_omniauth
28
+ add_omniauth_callback_routes
29
+ add_omniauth_callback_controller
30
+ configure_and_add_devise_setting_in_user_model
31
+ show_readme
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
6
+ For example:
7
+
8
+ Rails.application.routes.draw do
9
+ devise_for :users, controllers: {
10
+ omniauth_callbacks: "users/omniauth_callbacks"
11
+ }
12
+ end
13
+
14
+ 2. Update the devise google omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
15
+ after registering the Rails application on: https://code.google.com/apis/console/
16
+ For example:
17
+
18
+ config.omniauth :google_auth, "APP_ID", "APP_SECRET"
19
+
20
+ 3. Your omniauth callback URL will be: `<host>/users/auth/google_oauth2/callback`. Please update
21
+ callback URL in Google after registering your omniauth application.
22
+
23
+ ===============================================================================