boring_generators 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 359acba051da88cd0afd42b265845dd57da2ac688e57466cfca79a87fdba8dec
4
- data.tar.gz: cf6b4543e010b57774ce160a49e02c962b4c90b1764cd6ff504725dffeced453
3
+ metadata.gz: e3e2cf89c148c10914b919c1f9be41275681aa3ba8eaed7a22df5beb6adbef55
4
+ data.tar.gz: '083314c373aeb284b779aba16629fa36cbbeb9f60521161d0f1de081b7c1f99a'
5
5
  SHA512:
6
- metadata.gz: a0895d2a677ff5c80e2249a0f5dca86f6f1ab1b74b0d53e2d08d5c2f8f437daef054511e4b6a6c15854e40721e5a21e81a41dec74267a072031628ecb86332fa
7
- data.tar.gz: 5e31f9a9804338af68046deb67f081e5754a9a09b2b61c651eb0191e259936878af814ff67241234ea802a4311887a8ed81cf7e5354514ba88333f8c585d6674
6
+ metadata.gz: a2f943d1a4fdda23f2a1905a3491f11e5aa8adde05371b24f91c20daa3dc7355a4d1a51e9d82243b642c2ddb5e738a5885369b034c79e87f801078186cf645b5
7
+ data.tar.gz: 4b1f672d170a27bd8782e423b228a45974ad5c6a2e8262adbfe91a109cc29b10f449d20176c8113201db119363fa3b035ce7707a71365ecfb391ee1a18a77cb8
@@ -10,11 +10,11 @@ jobs:
10
10
  - name: Set up Ruby
11
11
  uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7.0
13
+ ruby-version: 2.7.3
14
14
  bundler-cache: true
15
15
  - name: Install Imagemagick
16
16
  run: |
17
- wget https://raw.githubusercontent.com/discourse/discourse_docker/master/image/base/install-imagemagick
17
+ wget https://raw.githubusercontent.com/discourse/discourse_docker/main/image/base/install-imagemagick
18
18
  chmod +x install-imagemagick
19
19
  sudo ./install-imagemagick
20
20
  - name: Install gems
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  .byebug_history
11
11
 
12
12
  *.log
13
+ .idea
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.13.0 (March 26th, 2024)
6
+ * Adds Letter Opener generator. ([@coolprobn][])
7
+ * Adds Whenever generator. ([@aadil][])
8
+ * Adds Rswag generator. ([@coolprobn][])
9
+ * Adds Webmock generator. ([@aadil][])
10
+
5
11
  ## 0.12.0 (May 8th, 2023)
6
12
  * Adds Flipper generator. ([@abhaynikam][])
7
13
  * Adds FactoryBot generator. ([@abhaynikam][])
@@ -77,3 +83,4 @@
77
83
  [@jamesglover]: https://github.com/JamesGlover
78
84
  [@luathn]: https://github.com/luathn
79
85
  [@coolprobn]: https://github.com/coolprobn
86
+ [@aadil]: https://github.com/AdilRT
data/CONTRIBUTING.md CHANGED
@@ -18,3 +18,20 @@ Push to your fork. Write a [good commit message][commit]. Submit a pull request.
18
18
 
19
19
  Please do not self reject your thoughts. Let's discuss even smallest feature request as well and make
20
20
  this package better for everybody's use.
21
+
22
+ ## Notes for Local Development of the Gem
23
+
24
+ ### While running Tests
25
+
26
+ When running tests, we normally do `bundle exec ruby -w -I test test/generators/rswag_install_generator_test.rb` to run a single test where "rswag_install_generator_test.rb" is the file name of the test we want to run.
27
+
28
+ And if your global ruby version is not the same as the "tmp/templates/app_template" where we run tests and make changes, tests might fail due to mismatch of ruby version and required gems not being installed correctly.
29
+
30
+ To tackle this issue you can add `.ruby-version` to the gem root by specifying the ruby version app_template is using. If you use rbenv this can be done with `rbenv local 2.7.0` where "2.7.0" is the app_template ruby-version at the moment.
31
+
32
+ We shouldn't commit this ".ruby-version" file to git since it's only intended for running tests. So to ignore this file from the git just for you, you can do the following:
33
+
34
+ - Open the git exclude file `nano .git/info/exclude`
35
+ - Add the file name ".ruby-version" to the end of the file and save it.
36
+
37
+ Now .ruby-version will be ignored by the git in your local machine just for this project.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boring_generators (0.11.0)
4
+ boring_generators (0.12.0)
5
5
  railties
6
6
 
7
7
  GEM
@@ -143,4 +143,4 @@ DEPENDENCIES
143
143
  sqlite3 (~> 1.4)
144
144
 
145
145
  BUNDLED WITH
146
- 2.3.12
146
+ 2.1.4
data/README.md CHANGED
@@ -37,9 +37,14 @@ And then you can use it this way:
37
37
  $ boring generate boring:simple_form:install --css_framework=<css_framework>
38
38
  $ boring g boring:pry:install
39
39
 
40
+ To see options provided by each generator with their descriptions and accepted values, you can hit the following command for example:
41
+
42
+ $ boring generate boring:simple_form:install --help
43
+
40
44
  ## Usage
41
45
 
42
46
  The boring generator introduces following generators:
47
+
43
48
  - [Install Tailwind CSS](https://www.boringgenerators.com/blog/2020-10-18-install-tailwind/): `rails generate boring:tailwind:install`
44
49
  - [Install Bootstrap](https://www.boringgenerators.com/blog/2020-11-15-install-bootstrap/): `rails generate boring:bootstrap:install`
45
50
  - Install JQuery: `rails generate boring:jquery:install`
@@ -75,6 +80,10 @@ The boring generator introduces following generators:
75
80
  - Install FactoryBot: `rails generate boring:factory_bot:install`
76
81
  - Install Faker: `rails generate boring:faker:install`
77
82
  - Install Overcommit with RuboCop: `rails generate boring:overcommit:pre_commit:rubocop:install`
83
+ - Install Letter Opener: `rails generate boring:letter_opener:install`
84
+ - Install Whenever: `rails generate boring:whenever:install`
85
+ - Install Rswag: `rails generate boring:rswag:install --rails_port=<rails_app_port> --authentication_type=<api_authentication_type> --skip_api_authentication=<skip_api_authentication> --api_authentication_options=<api_authentication_options> --enable_swagger_ui_authentication=<enable_swagger_ui_authentication>`
86
+ - Install Webmock: `rails generate boring:webmock:install --app_test_framework=<test_framework>`
78
87
 
79
88
  ## Screencasts
80
89
 
@@ -1,3 +1,3 @@
1
1
  module BoringGenerators
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module LetterOpener
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds letter_opener gem for previewing email in development environment"
7
+
8
+ def add_letter_opener_gem
9
+ say "Adding letter_opener gem", :green
10
+
11
+ gem_content = <<~RUBY
12
+ \t# Preview email in the default browser instead of sending it to real mailbox
13
+ \tgem "letter_opener"
14
+ RUBY
15
+
16
+ insert_into_file "Gemfile", gem_content, after: /group :development do/
17
+
18
+ Bundler.with_unbundled_env do
19
+ run "bundle install"
20
+ end
21
+ end
22
+
23
+ def configure_letter_opener
24
+ say "Configuring letter_opener", :green
25
+
26
+ configuration_content = <<~RUBY.chomp
27
+ \n\t# Preview email in the browser instead of sending it
28
+ \tconfig.action_mailer.delivery_method = :letter_opener
29
+ \tconfig.action_mailer.perform_deliveries = true
30
+ end
31
+ RUBY
32
+
33
+ gsub_file "config/environments/development.rb",
34
+ /end\Z/,
35
+ configuration_content
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Rswag
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds rswag gem to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ class_option :rails_port,
10
+ type: :string,
11
+ desc: "Tell us the port number where you normally run your rails app. Defaults to PORT 3000",
12
+ default: "3000"
13
+ class_option :authentication_type,
14
+ type: :string,
15
+ desc: "Tell us the authentication type you use in your rails app. Options: ['basic', 'bearer', 'api_key']. Defaults to 'basic'",
16
+ default: 'basic'
17
+ class_option :skip_api_authentication,
18
+ type: :boolean,
19
+ desc: "Use this option with value 'true' if you don't want to add Authentication when making API calls via swagger docs.",
20
+ default: false
21
+ class_option :api_authentication_options,
22
+ type: :hash,
23
+ desc: 'Use together with authentication_type. Required for "api_key" authentication which has dynamic set of options. See: https://swagger.io/docs/specification/authentication. Example: "--api_authentication_options=name:api_key in:header"'
24
+ class_option :enable_swagger_ui_authentication,
25
+ type: :boolean,
26
+ desc: "Use this option with value 'true' for securing your API docs behind a basic authentication to block unauthorized access",
27
+ default: false
28
+
29
+ def verify_presence_of_rspec_gem
30
+ gem_file_content_array = File.readlines("Gemfile")
31
+
32
+ rspec_is_installed = gem_file_content_array.any? { |line| line.include?("rspec-rails") }
33
+
34
+ return if rspec_is_installed
35
+
36
+ say "We couldn't find rspec-rails gem which is a dependency for the rswag gem. Please configure rspec and run the generator again!"
37
+
38
+ abort
39
+ end
40
+
41
+ def add_rswag_gems
42
+ say "Adding rswag gems to Gemfile", :green
43
+
44
+ gem 'rswag-api'
45
+ gem 'rswag-ui'
46
+ gem 'rswag-specs', group: [:development, :test]
47
+ end
48
+
49
+ def install_rswag
50
+ say "\nRunning rswag install generator to add required files", :green
51
+
52
+ Bundler.with_unbundled_env do
53
+ run 'bundle install'
54
+
55
+ generate 'rswag:api:install'
56
+ generate 'rswag:ui:install'
57
+ generate 'rswag:specs:install', [env: 'test']
58
+ end
59
+ end
60
+
61
+ def update_api_host
62
+ say "\nUpdating API Host URL", :green
63
+
64
+ rails_port = options[:rails_port]
65
+
66
+ gsub_file "spec/swagger_helper.rb",
67
+ "url: 'https://{defaultHost}'",
68
+ "url: 'http://{defaultHost}'"
69
+ gsub_file "spec/swagger_helper.rb",
70
+ "default: 'www.example.com'",
71
+ "default: 'localhost:#{rails_port}'"
72
+ end
73
+
74
+ def add_authentication_scheme
75
+ if options[:skip_api_authentication]
76
+ return
77
+ end
78
+
79
+ say "\nAdding Authentication for APIs", :green
80
+
81
+ authentication_type = options[:authentication_type]
82
+
83
+ if authentication_type == 'api_key'
84
+ validate_api_authentication_options
85
+
86
+ authentication_options = options[:api_authentication_options]
87
+ end
88
+
89
+ authentication_content = case authentication_type
90
+ when 'bearer'
91
+ <<~RUBY.chomp.indent(0)
92
+ type: :http,
93
+ scheme: :bearer
94
+ RUBY
95
+ when 'api_key'
96
+ <<~RUBY
97
+ type: :apiKey,
98
+ name: "#{authentication_options['name']}",
99
+ in: "#{authentication_options['in']}",
100
+ RUBY
101
+ else
102
+ <<~RUBY
103
+ type: :http,
104
+ scheme: :basic
105
+ RUBY
106
+ end
107
+
108
+ gsub_file "spec/swagger_helper.rb",
109
+ /servers: \[.*\]/m do |match|
110
+ configuration_content = <<~RUBY.indent(6)
111
+ components: {
112
+ securitySchemes: {
113
+ authorization: {\n#{authentication_content.chomp.indent(6)}
114
+ }
115
+ }
116
+ },
117
+ security: [
118
+ authorization: []
119
+ ]
120
+ RUBY
121
+
122
+ match << ",\n#{configuration_content.chomp}"
123
+ end
124
+ end
125
+
126
+ def enable_swagger_ui_authentication
127
+ return unless options[:enable_swagger_ui_authentication]
128
+
129
+ say "\nAdding Basic Authentication to secure the UI", :green
130
+
131
+ uncomment_lines 'config/initializers/rswag_ui.rb', /c.basic_auth_enabled/
132
+ uncomment_lines 'config/initializers/rswag_ui.rb', /c.basic_auth_credentials/
133
+ gsub_file "config/initializers/rswag_ui.rb",
134
+ "c.basic_auth_credentials 'username', 'password'",
135
+ 'c.basic_auth_credentials Rails.application.credentials.dig(:swagger_ui, :username), Rails.application.credentials.dig(:swagger_ui, :password)'
136
+
137
+ say "❗️❗️\nusername will be used from `Rails.application.credentials.dig(:swagger_ui, :username)` and password from `Rails.application.credentials.dig(:swagger_ui, :password)`. You can change these values if they don't match with your app.\n", :yellow
138
+ end
139
+
140
+ def show_readme
141
+ readme "README"
142
+ end
143
+
144
+ private
145
+
146
+ def validate_api_authentication_options
147
+ api_authentication_options = options[:api_authentication_options]
148
+
149
+ if api_authentication_options.blank?
150
+ say "api_authentication_options args should be provided for api_key authentication", :red
151
+
152
+ abort
153
+ end
154
+
155
+ missing_options = %w[name in] - api_authentication_options.keys
156
+
157
+ if missing_options.length.positive?
158
+ say "Option/s '#{missing_options.join(', ')}' should be present for api_key authentication!", :red
159
+ say 'Example of valid options: "--api_authentication_options=name:api_key in:query"', :yellow
160
+
161
+ abort
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,10 @@
1
+ ===============================================================================
2
+
3
+ To get up and running with rswag you can do the following next:
4
+
5
+ 1. Write a rswag spec by following instructions from Getting Started guide at https://github.com/rswag/rswag#getting-started
6
+ 2. Once the spec is ready, generate the swagger file with `rails rswag`
7
+ 3. Run the rails server with `rails s`
8
+ 4. Assuming your app is at "localhost:3000", you will find your API docs at `http://localhost:3000/api-docs/index.html`
9
+
10
+ ===============================================================================
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ module Boring
3
+ module Webmock
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Adds webmock gem to the application"
6
+
7
+ SUPPORTED_TEST_FRAMEWORKS = %w[rspec minitest]
8
+
9
+ # can't use "test_framework" option which would be a good naming for this because it's being used by Rails::Generator::Base. It's better not to have any conflict with the base class so prefixing with "app_" here
10
+ class_option :app_test_framework,
11
+ type: :string,
12
+ desc: "Tell us the framework you use for writing tests in your application. Supported options are #{SUPPORTED_TEST_FRAMEWORKS}",
13
+ default: "minitest"
14
+
15
+ def verify_test_framework_configurations
16
+ app_test_framework = options[:app_test_framework]
17
+
18
+ if app_test_framework.blank?
19
+ say <<~WARNING, :red
20
+ ERROR: Unsupported test framework: #{app_test_framework}
21
+ WARNING
22
+
23
+ abort
24
+ else
25
+ verify_presence_of_test_framework
26
+ end
27
+ end
28
+
29
+ def add_webmock_gem
30
+ say "Adding webmock gem", :green
31
+
32
+ gem "webmock"
33
+
34
+ Bundler.with_unbundled_env do
35
+ run "bundle install"
36
+ end
37
+ end
38
+
39
+ def configure_webmock
40
+ app_test_framework = options[:app_test_framework]
41
+
42
+ say "Configuring webmock", :green
43
+
44
+ if app_test_framework == "minitest"
45
+ configure_minitest
46
+ else
47
+ configure_rspec
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def verify_presence_of_test_framework
54
+ app_test_framework = options[:app_test_framework]
55
+ test_framework_folder = { minitest: "test", rspec: "spec" }.dig(app_test_framework.to_sym) || ''
56
+
57
+ test_folder_is_present = Dir.exist?(test_framework_folder) && Dir.entries(test_framework_folder).length.positive?
58
+
59
+ return if test_folder_is_present
60
+
61
+ say "We couldn't find #{test_framework_folder} in your project. Please make sure #{app_test_framework} is configured correctly and run the generator again!", :red
62
+
63
+ abort
64
+ end
65
+
66
+ def configure_minitest
67
+ inject_into_file 'test/test_helper.rb',
68
+ before: /\n(class|module) ActiveSupport/ do
69
+ <<~RUBY
70
+ \nrequire 'webmock/minitest'
71
+ WebMock.disable_net_connect!(allow_localhost: true)
72
+ RUBY
73
+ end
74
+ end
75
+
76
+ def configure_rspec
77
+ inject_into_file "spec/spec_helper.rb",
78
+ "require 'webmock/rspec'\n\n",
79
+ before: /\A/
80
+ inject_into_file "spec/spec_helper.rb",
81
+ "\tWebMock.disable_net_connect!(allow_localhost: true)\n\n",
82
+ after: "RSpec.configure do |config|\n"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Whenever
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds whenever gem to the application for managing cron jobs"
7
+
8
+ def add_whenever_gem
9
+ say "Adding whenever gem", :green
10
+
11
+ Bundler.with_unbundled_env do
12
+ run "bundle add whenever"
13
+ end
14
+ end
15
+
16
+ def add_schedule_file
17
+ say "Create schedule.rb file", :green
18
+
19
+ Bundler.with_unbundled_env do
20
+ run "bundle exec wheneverize ."
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.7.3
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- ruby '2.7.0'
4
+ ruby '2.7.3'
5
5
 
6
6
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7
7
  gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
@@ -1 +1 @@
1
- require "rails/all"
1
+ require "bundler/setup" # Set up gems listed in the Gemfile.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boring_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhay Nikam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -87,6 +87,7 @@ files:
87
87
  - lib/generators/boring/graphql/install/templates/base_resolver.rb
88
88
  - lib/generators/boring/graphql/install/templates/hello_world_resolver.rb
89
89
  - lib/generators/boring/jquery/install/install_generator.rb
90
+ - lib/generators/boring/letter_opener/install/install_generator.rb
90
91
  - lib/generators/boring/oauth/base_generator.rb
91
92
  - lib/generators/boring/oauth/facebook/install/install_generator.rb
92
93
  - lib/generators/boring/oauth/facebook/install/templates/README
@@ -115,6 +116,8 @@ files:
115
116
  - lib/generators/boring/pundit/install/install_generator.rb
116
117
  - lib/generators/boring/rails_admin/install/install_generator.rb
117
118
  - lib/generators/boring/rspec/install/install_generator.rb
119
+ - lib/generators/boring/rswag/install/install_generator.rb
120
+ - lib/generators/boring/rswag/install/templates/README
118
121
  - lib/generators/boring/rubocop/install/install_generator.rb
119
122
  - lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt
120
123
  - lib/generators/boring/simple_form/install/install_generator.rb
@@ -125,6 +128,8 @@ files:
125
128
  - lib/generators/boring/twilio/install/install_generator.rb
126
129
  - lib/generators/boring/twilio/install/templates/README
127
130
  - lib/generators/boring/twilio/install/templates/twilio.rb
131
+ - lib/generators/boring/webmock/install/install_generator.rb
132
+ - lib/generators/boring/whenever/install/install_generator.rb
128
133
  - tmp/templates/app_template/.ruby-version
129
134
  - tmp/templates/app_template/Gemfile
130
135
  - tmp/templates/app_template/README.md