boring_generators 0.13.0 → 0.15.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +83 -49
  3. data/Gemfile.lock +2 -2
  4. data/README.md +14 -0
  5. data/lib/boring_generators/generator_helper.rb +46 -0
  6. data/lib/boring_generators/version.rb +1 -1
  7. data/lib/generators/boring/active_storage/azure/install/install_generator.rb +1 -1
  8. data/lib/generators/boring/annotate/install/install_generator.rb +52 -0
  9. data/lib/generators/boring/audit/install/install_generator.rb +1 -1
  10. data/lib/generators/boring/avo/install/install_generator.rb +25 -0
  11. data/lib/generators/boring/cancancan/install/install_generator.rb +34 -0
  12. data/lib/generators/boring/ci/gitlab_ci/install/install_generator.rb +120 -0
  13. data/lib/generators/boring/ci/gitlab_ci/install/templates/README +10 -0
  14. data/lib/generators/boring/ci/gitlab_ci/install/templates/capybara_helper.rb.tt +42 -0
  15. data/lib/generators/boring/ci/gitlab_ci/install/templates/ci.yml.tt +94 -0
  16. data/lib/generators/boring/ci/gitlab_ci/install/templates/database.yml.ci.tt +20 -0
  17. data/lib/generators/boring/ci/gitlab_ci/install/templates/system_sample_spec.rb.tt +14 -0
  18. data/lib/generators/boring/ci/gitlab_ci/install/templates/system_sample_test.rb.tt +13 -0
  19. data/lib/generators/boring/ci/gitlab_ci/install/templates/unit_sample_spec.rb.tt +7 -0
  20. data/lib/generators/boring/ci/gitlab_ci/install/templates/unit_sample_test.rb.tt +7 -0
  21. data/lib/generators/boring/devise/doorkeeper/install/install_generator.rb +190 -0
  22. data/lib/generators/boring/devise/install/install_generator.rb +42 -9
  23. data/lib/generators/boring/dotenv/install/install_generator.rb +51 -0
  24. data/lib/generators/boring/dotenv/install/templates/.env +3 -0
  25. data/lib/generators/boring/factory_bot/install/install_generator.rb +1 -1
  26. data/lib/generators/boring/faker/install/install_generator.rb +1 -1
  27. data/lib/generators/boring/favicon/build/build_generator.rb +1 -1
  28. data/lib/generators/boring/figjam/install/install_generator.rb +33 -0
  29. data/lib/generators/boring/honeybadger/install/install_generator.rb +47 -0
  30. data/lib/generators/boring/honeybadger/install/templates/README +6 -0
  31. data/lib/generators/boring/honeybadger/install/templates/honeybadger.yml.tt +26 -0
  32. data/lib/generators/boring/letter_opener/install/install_generator.rb +8 -9
  33. data/lib/generators/boring/oauth/google/install/install_generator.rb +2 -2
  34. data/lib/generators/boring/pronto/base_generator.rb +78 -0
  35. data/lib/generators/boring/pronto/github_action/install/install_generator.rb +27 -0
  36. data/lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt +53 -0
  37. data/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb +112 -0
  38. data/lib/generators/boring/pronto/gitlab_ci/install/templates/.gitlab-ci.yml.tt +22 -0
  39. data/lib/generators/boring/pronto/gitlab_ci/install/templates/README +7 -0
  40. data/lib/generators/boring/rack_mini_profiler/install/install_generator.rb +38 -0
  41. data/lib/generators/boring/rails_erd/install/install_generator.rb +35 -0
  42. data/lib/generators/boring/rspec/install/install_generator.rb +1 -1
  43. data/lib/generators/boring/sentry/install/install_generator.rb +48 -0
  44. data/lib/generators/boring/sentry/install/templates/sentry.rb +7 -0
  45. data/lib/generators/boring/vcr/install/install_generator.rb +126 -0
  46. data/lib/generators/boring/vcr/install/templates/rspec/vcr.rb.tt +9 -0
  47. data/lib/generators/boring/webmock/install/install_generator.rb +7 -6
  48. metadata +34 -2
@@ -0,0 +1,94 @@
1
+ image: ruby:<%= @ruby_version %>
2
+
3
+ variables:
4
+ MASTER_KEY: $MASTER_KEY
5
+
6
+ cache:
7
+ paths:
8
+ - vendor/
9
+ <%- if File.exist?("package.json") -%>
10
+ - node_modules/
11
+ - yarn.lock
12
+ <%- end -%>
13
+
14
+ stages:
15
+ - test
16
+
17
+ .base_db:
18
+ <%- if @database == "postgresql" -%>
19
+ services:
20
+ - postgres:latest
21
+ <%- elsif @database == "mysql" -%>
22
+ services:
23
+ - mysql:latest
24
+ <%- end -%>
25
+ variables:
26
+ RAILS_ENV: test
27
+ <%- if @database == "postgresql" -%>
28
+ POSTGRES_HOST_AUTH_METHOD: trust
29
+ <%- end -%>
30
+ <%- if @database == "mysql" -%>
31
+ MYSQL_ALLOW_EMPTY_PASSWORD: true
32
+ <%- end -%>
33
+ before_script:
34
+ - gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)" --no-document
35
+ - bundle config set --local path 'vendor'
36
+ <%- if File.exist?("package.json") -%>
37
+ - apt-get update -qq && apt-get install -y -qq nodejs
38
+ - curl -o- -L https://yarnpkg.com/install.sh | bash
39
+ - export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
40
+ - yarn install --pure-lockfile
41
+ <%- end -%>
42
+ <%- if @database == "sqlite3" -%>
43
+ - apt-get update && apt-get install --no-install-recommends -y sqlite3
44
+ <%- end -%>
45
+ - apt-get update && apt-get install --no-install-recommends -y cmake
46
+ - bundle install --jobs $(nproc)
47
+ - cp config/database.yml.ci config/database.yml
48
+ <%- if @environment_variable_manager == "dotenv" -%>
49
+ - cat $env > .env
50
+ <%- elsif @environment_variable_manager == "figjam" -%>
51
+ - cat $env > config/application.yml
52
+ <%- end -%>
53
+ - bundle exec rails db:test:prepare
54
+
55
+ unit_and_integration_tests:
56
+ extends: .base_db
57
+ stage: test
58
+ only:
59
+ - merge_requests
60
+ script:
61
+ <%- if @app_test_framework == "rspec" -%>
62
+ - bundle exec rspec --exclude-pattern "spec/system/**/*.rb"
63
+ <%- else -%>
64
+ - bundle exec rails test
65
+ <%- end -%>
66
+
67
+ system_tests:
68
+ extends: .base_db
69
+ stage: test
70
+ services:
71
+ - name: selenium/standalone-chrome:latest
72
+ alias: selenium
73
+ <%- if @database == "postgresql" -%>
74
+ - postgres:latest
75
+ <%- elsif @database == "mysql" -%>
76
+ - mysql:latest
77
+ <%- end -%>
78
+ variables:
79
+ RAILS_ENV: test
80
+ SELENIUM_REMOTE_URL: http://selenium:4444/wd/hub
81
+ only:
82
+ - merge_requests
83
+ script:
84
+ <%- if @app_test_framework == "rspec" -%>
85
+ - bundle exec rspec spec/system
86
+ <%- else -%>
87
+ - bundle exec rails test:system
88
+ <%- end -%>
89
+ artifacts:
90
+ when: on_failure
91
+ paths:
92
+ - log/test.log
93
+ - tmp/screenshots/
94
+ expire_in: 1 week
@@ -0,0 +1,20 @@
1
+ test:
2
+ <%- if @database == "postgresql" -%>
3
+ adapter: postgresql
4
+ encoding: unicode
5
+ host: postgres
6
+ username: postgres
7
+ <%- elsif @database == "mysql" -%>
8
+ adapter: mysql2
9
+ encoding: utf8mb4
10
+ host: mysql
11
+ username: root
12
+ socket: /tmp/mysql.sock
13
+ <%- else -%>
14
+ adapter: sqlite3
15
+ database: db/test.sqlite3
16
+ <%- end -%>
17
+ <%- unless @database == "sqlite3" -%>
18
+ database: ci_db
19
+ <%- end -%>
20
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
@@ -0,0 +1,14 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe "Sample System Test", type: :system, js: true do
4
+ it "checks if the system test is configured correctly" do
5
+ visit rails_health_check_path
6
+
7
+ # expect page body to have green background
8
+ expect(
9
+ page.evaluate_script(
10
+ "window.getComputedStyle(document.body).backgroundColor"
11
+ )
12
+ ).to eq("rgb(0, 128, 0)")
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require "application_system_test_case"
2
+
3
+ class SampleTest < ApplicationSystemTestCase
4
+ test "checks if the system test is configured correctly" do
5
+ visit rails_health_check_path
6
+
7
+ # assert page body has green background
8
+ assert_equal "rgb(0, 128, 0)",
9
+ page.evaluate_script(
10
+ "window.getComputedStyle(document.body).backgroundColor"
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe("Sample", type: :model) do
4
+ it "tests the truth" do
5
+ expect(true).to be_truthy
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class SampleTest < ActiveSupport::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'boring_generators/generator_helper'
4
+
5
+ module Boring
6
+ module Devise
7
+ module Doorkeeper
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include BoringGenerators::GeneratorHelper
10
+
11
+ desc "Adds doorkeeper with devise to the application"
12
+
13
+ class_option :model_name, type: :string, aliases: "-m", default: "User",
14
+ desc: "Tell us the user model name which will be used for authentication. Defaults to User"
15
+ class_option :grant_flows, type: :array, aliases: "-gf", default: %w[authorization_code client_credentials],
16
+ enum: %w[authorization_code client_credentials password],
17
+ desc: "Tell us the grant flows you want to use separated by space. Defaults to authorization_code and client_credentials"
18
+ class_option :api_only, type: :boolean, aliases: "-a", default: false,
19
+ desc: "Tell us if you want to setup doorkeeper for API only application. Defaults to false"
20
+ class_option :skip_applications_routes, type: :boolean, aliases: "-sr", default: false,
21
+ desc: "Tell us if you want to skip adding doorkeeper routes to manage applications. Defaults to false"
22
+ class_option :use_refresh_token, type: :boolean, aliases: "-rt", default: false,
23
+ desc: "Keep user logged in with refresh tokens. Defaults to false"
24
+
25
+ def verify_presence_of_devise_gem
26
+ return if gem_installed?("devise")
27
+
28
+ say "We couldn't find devise gem. Please configure devise gem and rerun the generator. Consider running `rails generate boring:devise:install` to set up Devise.",
29
+ :red
30
+
31
+ abort
32
+ end
33
+
34
+ def verify_presence_of_devise_model
35
+ return if File.exist?("app/models/#{options[:model_name].underscore}.rb")
36
+
37
+ say "We couldn't find the #{options[:model_name]} model. Maybe there is a typo? Please provide the correct model name and run the generator again.",
38
+ :red
39
+
40
+ abort
41
+ end
42
+
43
+ def add_doorkeeper_gem
44
+ say "Adding doorkeeper gem", :green
45
+
46
+ check_and_install_gem "doorkeeper"
47
+ end
48
+
49
+ def run_doorkeeper_generators
50
+ say "Running doorkeeper generators", :green
51
+
52
+ Bundler.with_unbundled_env do
53
+ run "bundle exec rails generate doorkeeper:install"
54
+ run "bundle exec rails generate doorkeeper:migration"
55
+ end
56
+ end
57
+
58
+ def add_doorkeeper_related_association_to_model
59
+ model_name = options[:model_name].underscore
60
+ say "Adding doorkeeper related associations to the model file app/models/#{model_name}.rb",
61
+ :green
62
+ model_content = <<~RUBY
63
+ has_many :access_grants,
64
+ class_name: 'Doorkeeper::AccessGrant',
65
+ foreign_key: :resource_owner_id,
66
+ dependent: :delete_all # or :destroy if you need callbacks
67
+
68
+ has_many :access_tokens,
69
+ class_name: 'Doorkeeper::AccessToken',
70
+ foreign_key: :resource_owner_id,
71
+ dependent: :delete_all # or :destroy if you need callbacks
72
+ RUBY
73
+
74
+ inject_into_file "app/models/#{model_name}.rb",
75
+ optimize_indentation(model_content, 2),
76
+ after: "ApplicationRecord\n"
77
+ end
78
+
79
+ def update_doorkeeper_initializer
80
+ say "Updating doorkeeper initializer", :green
81
+
82
+ configure_resource_owner_authenticator if options[:grant_flows].include?("authorization_code")
83
+ configure_admin_authenticator unless options[:api_only] || options[:skip_applications_routes]
84
+ configure_resource_owner_from_credentials if options[:grant_flows].include?("password")
85
+
86
+ gsub_file "config/initializers/doorkeeper.rb",
87
+ /# grant_flows %w\[authorization_code client_credentials\]/,
88
+ "grant_flows %w[#{options[:grant_flows].uniq.join(' ')}]"
89
+
90
+ if options[:api_only]
91
+ gsub_file "config/initializers/doorkeeper.rb",
92
+ /# api_only/,
93
+ "api_only"
94
+ end
95
+
96
+ if options[:skip_applications_routes]
97
+ doorkeeper_routes_content = <<~RUBY
98
+ use_doorkeeper do
99
+ skip_controllers :applications, :authorized_applications
100
+ end
101
+ RUBY
102
+
103
+ gsub_file "config/routes.rb",
104
+ /.*use_doorkeeper/,
105
+ optimize_indentation(doorkeeper_routes_content, 2)
106
+ end
107
+
108
+ if options[:use_refresh_token]
109
+ uncomment_lines "config/initializers/doorkeeper.rb",
110
+ /use_refresh_token/
111
+ end
112
+ end
113
+
114
+ def update_doorkeeper_migration
115
+ say "Updating doorkeeper migration", :green
116
+ model_name = options[:model_name].underscore
117
+
118
+ uncomment_lines Dir["db/migrate/*_create_doorkeeper_tables.rb"].first,
119
+ /add_foreign_key :oauth/
120
+
121
+ gsub_file Dir["db/migrate/*_create_doorkeeper_tables.rb"].first,
122
+ /<model>/,
123
+ ":#{model_name.pluralize}"
124
+
125
+ return unless (%w[password client_credentials] & options[:grant_flows]).any?
126
+
127
+ gsub_file Dir["db/migrate/*_create_doorkeeper_tables.rb"].first,
128
+ /t.text :redirect_uri, null: false/,
129
+ "t.text :redirect_uri"
130
+ end
131
+
132
+ def show_message
133
+ return if options[:api_only] || options[:skip_applications_routes]
134
+
135
+ model_name = options[:model_name].underscore
136
+ admin_authenticator_content = "current_#{model_name} || warden.authenticate!(scope: :#{model_name})"
137
+
138
+ say "\nWe've implemented `#{admin_authenticator_content}` in the admin_authenticator block of config/initializers/doorkeeper.rb to manage access to application routes. Please adjust it as necessary to suit your requirements.",
139
+ :yellow
140
+ end
141
+
142
+ private
143
+
144
+ def configure_resource_owner_authenticator
145
+ model_name = options[:model_name].underscore
146
+ resource_owner_authenticator_content = <<~RUBY
147
+ resource_owner_authenticator do
148
+ current_#{model_name} || warden.authenticate!(scope: :#{model_name})
149
+ end
150
+ RUBY
151
+
152
+ gsub_file "config/initializers/doorkeeper.rb",
153
+ /.*resource_owner_authenticator do\n(?:\s|.)*?end/,
154
+ optimize_indentation(resource_owner_authenticator_content, 2)
155
+ end
156
+
157
+ def configure_admin_authenticator
158
+ model_name = options[:model_name].underscore
159
+ gsub_file "config/initializers/doorkeeper.rb",
160
+ /(?:# admin_authenticator do\n*)((?:\s|.)*?)(?:# end)/,
161
+ "admin_authenticator do\n" + "\\1" + "end"
162
+
163
+ admin_authenticator_content = "current_#{model_name} || warden.authenticate!(scope: :#{model_name})"
164
+ inject_into_file "config/initializers/doorkeeper.rb",
165
+ optimize_indentation(admin_authenticator_content, 4),
166
+ after: /admin_authenticator do\n/,
167
+ force: true
168
+
169
+ end
170
+
171
+ def configure_resource_owner_from_credentials
172
+ model_name = options[:model_name].underscore
173
+ resource_owner_for_credentials_content = <<~RUBY
174
+ resource_owner_from_credentials do |routes|
175
+ #{model_name} = #{options[:model_name]}.find_for_database_authentication(email: params[:email])
176
+ if #{model_name}&.valid_for_authentication? { #{model_name}.valid_password?(params[:password]) } && #{model_name}&.active_for_authentication?
177
+ request.env['warden'].set_user(#{model_name}, scope: :#{model_name}, store: false)
178
+ #{model_name}
179
+ end
180
+ end
181
+ RUBY
182
+
183
+ inject_into_file "config/initializers/doorkeeper.rb",
184
+ optimize_indentation(resource_owner_for_credentials_content, 2),
185
+ after: /resource_owner_authenticator do\n(?:\s|.)*?end\n/
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -7,18 +7,28 @@ module Boring
7
7
 
8
8
  DEFAULT_DEVISE_MODEL_NAME = "User"
9
9
 
10
- class_option :model_name, type: :string, aliases: "-m",
11
- desc: "Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}"
12
- class_option :skip_devise_view, type: :boolean, aliases: "-sv",
10
+ class_option :model_name,
11
+ type: :string,
12
+ aliases: "-m",
13
+ desc:
14
+ "Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}"
15
+ class_option :skip_devise_view,
16
+ type: :boolean,
17
+ aliases: "-sv",
13
18
  desc: "Skip generating devise views"
14
- class_option :skip_devise_model, type: :boolean, aliases: "-sm",
19
+ class_option :skip_devise_model,
20
+ type: :boolean,
21
+ aliases: "-sm",
15
22
  desc: "Skip generating devise model"
23
+ class_option :run_db_migrate,
24
+ type: :boolean,
25
+ aliases: "-rdm",
26
+ desc: "Run migrations after generating user table",
27
+ default: false
16
28
 
17
29
  def add_devise_gem
18
30
  say "Adding devise gem", :green
19
- Bundler.with_unbundled_env do
20
- run "bundle add devise"
21
- end
31
+ Bundler.with_unbundled_env { run "bundle add devise" }
22
32
  end
23
33
 
24
34
  def generating_devise_defaults
@@ -30,10 +40,12 @@ module Boring
30
40
 
31
41
  def add_devise_action_mailer_development_config
32
42
  say "Adding devise Action Mailer development configuration", :green
33
- insert_into_file "config/environments/development.rb", <<~RUBY, after: /Rails.application.configure do/
43
+ insert_into_file "config/environments/development.rb",
44
+ <<~RUBY,
34
45
  \n
35
46
  \tconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
36
47
  RUBY
48
+ after: /Rails.application.configure do/
37
49
  end
38
50
 
39
51
  def add_devise_user_model
@@ -45,13 +57,28 @@ module Boring
45
57
  Bundler.with_unbundled_env do
46
58
  run "DISABLE_SPRING=1 bundle exec rails generate devise #{model_name}"
47
59
  end
60
+
61
+ # make the email unique
62
+ if File.exist?("test/fixtures/users.yml")
63
+ email_content = <<~FIXTURE
64
+ one:
65
+ email: example-$LABEL@email.com
66
+ FIXTURE
67
+
68
+ gsub_file "test/fixtures/users.yml",
69
+ /one: {}/,
70
+ optimize_indentation(email_content, 0)
71
+ end
48
72
  end
49
73
 
50
74
  def add_devise_authentication_filter_to_application_controller
51
- insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/
75
+ insert_into_file "app/controllers/application_controller.rb",
76
+ <<~RUBY,
52
77
  \n
53
78
  \tbefore_action :authenticate_user!
54
79
  RUBY
80
+ after:
81
+ /class ApplicationController < ActionController::Base/
55
82
  end
56
83
 
57
84
  def add_devise_views
@@ -64,6 +91,12 @@ module Boring
64
91
  run "DISABLE_SPRING=1 bundle exec rails generate devise:views #{model_name.pluralize}"
65
92
  end
66
93
  end
94
+
95
+ def run_db_migrate
96
+ return unless options[:run_db_migrate]
97
+
98
+ Bundler.with_unbundled_env { rails_command "db:migrate" }
99
+ end
67
100
  end
68
101
  end
69
102
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "boring_generators/generator_helper"
4
+
5
+ module Boring
6
+ module Dotenv
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include BoringGenerators::GeneratorHelper
9
+
10
+ desc "Adds dotenv gem to the application"
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ def add_dotenv_gem
14
+ return if gem_installed?("dotenv-rails")
15
+
16
+ say "Adding dotenv gem", :green
17
+
18
+ check_and_install_gem "dotenv-rails", group: :development
19
+ end
20
+
21
+ def configure_dotenv_gem
22
+ say "Configuring dotenv gem", :green
23
+
24
+ template ".env", ".env"
25
+
26
+ create_file ".gitignore" unless File.exist?(".gitignore")
27
+
28
+ FileUtils.cp(".env", ".env.sample")
29
+
30
+ add_env_files_to_gitignore
31
+ end
32
+
33
+ private
34
+
35
+ def add_env_files_to_gitignore
36
+ if File.readlines(".gitignore").any? { |line| line.include?(".env") }
37
+ return
38
+ end
39
+
40
+ ignore_content = <<~ENV_FILE_NAMES
41
+ \n
42
+ # Ignore all environment files (except templates).
43
+ /.env
44
+ !/.env.*
45
+ ENV_FILE_NAMES
46
+
47
+ insert_into_file(".gitignore", ignore_content)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ # Add your environment variables here
2
+ # Example:
3
+ # SECRET_KEY_BASE=your_secret_key
@@ -14,7 +14,7 @@ module Boring
14
14
  def add_factory_bot_gem
15
15
  log :adding, "FactoryBot"
16
16
  Bundler.with_unbundled_env do
17
- run "bundle add factory_bot_rails --group='developement,test'"
17
+ run "bundle add factory_bot_rails --group='development,test'"
18
18
  end
19
19
  end
20
20
 
@@ -9,7 +9,7 @@ module Boring
9
9
  def add_faker_gem
10
10
  log :adding, "faker"
11
11
  Bundler.with_unbundled_env do
12
- run "bundle add faker --group='developement,test'"
12
+ run "bundle add faker --group='development,test'"
13
13
  end
14
14
  end
15
15
  end
@@ -39,7 +39,7 @@ module Boring
39
39
  end
40
40
 
41
41
  def create_favicon_directory
42
- unless File.exists?(FILE_FAVICO_DIR)
42
+ unless File.exist?(FILE_FAVICO_DIR)
43
43
  Dir.mkdir FILE_FAVICO_DIR
44
44
  end
45
45
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Figjam
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc 'Adds figjam gem to the app'
7
+
8
+ def add_figjam_gem
9
+ say 'Adding figjam gem', :green
10
+
11
+ Bundler.with_unbundled_env do
12
+ run 'bundle add figjam'
13
+ end
14
+ end
15
+
16
+ def configure_figjam
17
+ say 'Configuring figjam', :green
18
+
19
+ Bundler.with_unbundled_env do
20
+ run 'bundle exec figjam install'
21
+ end
22
+
23
+ FileUtils.cp('config/application.yml', 'config/application.yml.sample')
24
+
25
+ unless File.exist?('.gitignore')
26
+ create_file '.gitignore'
27
+ end
28
+
29
+ insert_into_file('.gitignore', "\n/config/application.yml\n")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Honeybadger
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+ desc 'Adds honeybadger to the app'
8
+
9
+ class_option :use_env_variable, type: :boolean, aliases: "-ev",
10
+ desc: 'Use ENV variable for devise_jwt_secret_key. By default Rails credentials will be used.'
11
+
12
+ def add_honeybadger_gem
13
+ say 'Adding Honeybadger gem', :green
14
+
15
+ Bundler.with_unbundled_env do
16
+ run 'bundle add honeybadger'
17
+ end
18
+ end
19
+
20
+ def configure_honeybadger_gem
21
+ say 'Setting up Honeybadger', :green
22
+
23
+ @api_key = honeybadger_api_key
24
+
25
+ template 'honeybadger.yml', 'config/honeybadger.yml'
26
+
27
+ show_readme
28
+ end
29
+
30
+ private
31
+
32
+ def show_readme
33
+ readme_template = File.read(File.join(self.class.source_root, 'README'))
34
+ readme_content = ERB.new(readme_template).result(binding)
35
+ say readme_content
36
+ end
37
+
38
+ def honeybadger_api_key
39
+ if options[:use_env_variable]
40
+ "ENV['HONEYBADGER_API_KEY']"
41
+ else
42
+ "Rails.application.credentials.dig(:honeybadger, :api_key)"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ ===============================================================================
2
+
3
+ The API key for Honeybadger will be used from <%= @api_key %>.
4
+ You can change these values if they don't match with your app.
5
+
6
+ ===============================================================================
@@ -0,0 +1,26 @@
1
+ ---
2
+ # For more options, see https://docs.honeybadger.io/lib/ruby/gem-reference/configuration
3
+
4
+ api_key: <%= @api_key %>
5
+
6
+ # The environment your app is running in.
7
+ env: "<%= Rails.env %>"
8
+
9
+ # The absolute path to your project folder.
10
+ root: "<%= Rails.root.to_s %>"
11
+
12
+ # Honeybadger won't report errors in these environments.
13
+ development_environments:
14
+ - test
15
+ - development
16
+ - cucumber
17
+
18
+ # By default, Honeybadger won't report errors in the development_environments.
19
+ # You can override this by explicitly setting report_data to true or false.
20
+ # report_data: true
21
+
22
+ # The current Git revision of your project. Defaults to the last commit hash.
23
+ # revision: null
24
+
25
+ # Enable verbose debug logging (useful for troubleshooting).
26
+ debug: false