next_rails 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,4 +1,7 @@
1
1
  ---
2
+ SHA256:
3
+ metadata.gz: e37620e9fa92eea06f9faa05a1ace3cd1b9ff2585da96b838e165f1b98b06129
4
+ data.tar.gz: 47335d3ccaf72cfb828deeeab67ae93700fe83f38a7aeb7194ddccad5ebb0f3d
2
5
  SHA512:
3
- metadata.gz: 26b0f59466fa7156a8a4c1087558b32e6f5bc628b70b3b1a377bc1465eebb16123a59bfb9a4885c63e1028c003b58aa2ad1d2e638bc95d3a729b8cfae21b162a
4
- data.tar.gz: a2c14a411a7f998e65b5af169adbe08148c1f2f3acf1b244ddfd4d883391c46840b38200ac3014ae9bb39333aecea572fbaf5d8efe46ade92a36f40db643c85d
6
+ metadata.gz: d449a18c9279d4bc1a2889440843c800dc5f8b1e1d50cacdb2ace1cdebb5b7eb7c14fb6247059e30f7e39412bbb97f15d5ec7b674320bf8bc8c840edf1144fa2
7
+ data.tar.gz: 8b22f60cdb23275ee943e68835374ea18c54d4ecb1718db2f2e9b0b701bad9a73da2dcc73c03438ed0269b610ed67bbcd7b5bd2eb9906d2c758394abbe0bf8e3
@@ -0,0 +1,51 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: "[BUG] "
5
+ labels: bug
6
+ assignees: ""
7
+ ---
8
+
9
+ **IMPORTANT: please make sure you ask yourself all intro questions and fill all sections of the template.**
10
+
11
+ **Before we start...:**
12
+
13
+ - [ ] I checked the documentation and found no answer
14
+ - [ ] I checked to make sure that this issue has not already been filed
15
+ - [ ] I'm reporting the issue to the correct repository (for multi-repository projects)
16
+
17
+ **Version, Branch, or Commit:**
18
+
19
+ What branch/commit/version of "next_rails" you are using?
20
+
21
+ **Expected behavior:**
22
+
23
+ Please include a detailed description of the behavior you were expecting when you encountered this issue.
24
+
25
+ **Actual behavior:**
26
+
27
+ Please include a detailed description of the actual behavior of the application.
28
+
29
+ **Steps to reproduce:**
30
+
31
+ How do I achieve this behavior? Use the following format to provide a step-by-step guide:
32
+
33
+ 1. Step 1: ...
34
+ 2. Step 2: ...
35
+
36
+ **Context and environment:**
37
+
38
+ Provide any relevant information about your setup (Customize the list accordingly based on what info is relevant to this project)
39
+
40
+ 1. Version of the software the issue is being opened for.
41
+ 2. Operating System
42
+ 3. Operating System version
43
+ 4. Ruby version
44
+
45
+ _Delete any information that is not relevant._
46
+
47
+ **Logs**
48
+
49
+ Include relevant log snippets or files here.
50
+
51
+ **I will abide by the [code of conduct](https://github.com/fastruby/next_rails/blob/main/CODE_OF_CONDUCT.md)**
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: Feature request
3
+ about: Request a new feature
4
+ title: "[REQUEST]"
5
+ labels: enhancement
6
+ assignees: ""
7
+ ---
8
+
9
+ **IMPORTANT: please make sure you ask yourself all intro questions and fill all sections of the template.**
10
+
11
+ **Before we start...:**
12
+
13
+ - [ ] I checked the documentation and didn't find this feature
14
+ - [ ] I checked to make sure that this feature has not already been requested
15
+
16
+ **Branch/Commit:**
17
+
18
+ Inform what branch/commit/version of "next_rails" you are using.
19
+
20
+ **Describe the feature:**
21
+
22
+ Please include a detailed description of the feature you are requesting and any detail on it’s expected behavior.
23
+
24
+ > **As a \<role name\>** > **I do \<something\>** > **And then I do \<another action\>** > **And I see \<some result\>**
25
+
26
+ **Problem:**
27
+
28
+ Please include a detailed description of the problem this feature would solve.
29
+
30
+ > **As a \<role name\>** > **I want to \<do something\>** > **So that I can achieve a \<goal\>**
31
+
32
+ **Mockups:**
33
+
34
+ Include any mockup idea related to the requested feature if it applies.
35
+
36
+ **Resources:**
37
+
38
+ If you have resources related to the implementation or research for this feature, add them here.
39
+
40
+ **I will abide by the [code of conduct](https://github.com/fastruby/next_rails/blob/main/CODE_OF_CONDUCT.md)**
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler"
9
+ directory: "/"
10
+ schedule:
11
+ interval: "daily"
@@ -0,0 +1,20 @@
1
+ name: Run rake task
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby-version: [3.1, 2.7.5]
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby ${{ matrix.ruby-version }}
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby-version }}
18
+ bundler-cache: true
19
+ - name: Run rake task
20
+ run: bundle exec rake
data/.travis.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.10
5
4
  - 2.3.3
5
+ - 2.4.10
6
+ - 2.5.8
7
+ - 2.6.6
8
+ - 2.7.2
9
+ - 3.0.2
6
10
  before_install: gem install bundler -v 1.16.1
data/CHANGELOG.md CHANGED
@@ -1,9 +1,38 @@
1
- # main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.0.3...main)
1
+ # main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.0.4...main)
2
+
3
+ * [FEATURE: Try to find the latest **compatible** version of a gem if the latest version is not compatible with the desired Rails version when checking compatibility](https://github.com/fastruby/next_rails/pull/49)
4
+
5
+ * [FEATURE: Added option --version to get the version of the gem being used](https://github.com/fastruby/next_rails/pull/38)
6
+
7
+ * [Added github action workflow](https://github.com/fastruby/next_rails/pull/40)
8
+
9
+ * [FEATURE: Add support to use DeprecationTracker with Minitest](Add support to use DeprecationTracker with Minitest)
10
+
11
+ * [FEATURE: Add dependabot](https://github.com/fastruby/next_rails/pull/41)
12
+
13
+ * [DOCUMENTATION: Update the code of conduct link in PR template](https://github.com/fastruby/next_rails/pull/46)
14
+
15
+ * [DOCUMENTATION: Add FEATURE REQUEST and BUG REPORT templates ](https://github.com/fastruby/next_rails/pull/48)
16
+
17
+ * [BUGFIX: Make behavior arguments optional](https://github.com/fastruby/next_rails/pull/44)
18
+
19
+ * [FEATURE: Command line option to check for recommended ruby version for the desired Rails version](https://github.com/fastruby/next_rails/pull/39)
20
+
21
+
22
+ # v1.0.5 / 2022-03-29 [(commits)](https://github.com/fastruby/next_rails/compare/v1.0.4...v1.0.5)
23
+
24
+ * [FEATURE: Initialize the Gemfile.next.lock to avoid major version jumps when used without an initial Gemfile.next.lock](https://github.com/fastruby/next_rails/pull/25)
25
+ * [FEATURE: Drop `actionview` dependency because it is not really used](https://github.com/fastruby/next_rails/pull/26)
26
+ * [BUGFIX: If shitlist path does not exist, create it for the user of the gem](https://github.com/fastruby/next_rails/pull/37)
27
+
28
+ # v1.0.4 / 2021-04-09 [(commits)](https://github.com/fastruby/next_rails/compare/v1.0.3...v1.0.4)
29
+
30
+ * [BUGFIX: Fixes issue with `bundle_report` and `actionview`](https://github.com/fastruby/next_rails/pull/22)
2
31
 
3
32
  # v1.0.3 / 2021-04-05 [(commits)](https://github.com/fastruby/next_rails/compare/v1.0.2...v1.0.3)
4
33
 
5
- * [BUGFIX] Update README.md to better document this `ten_years_rails` fork (by [@etagwerker][])
6
- * [BUGFIX] Make ActionView an optional dependency (by [@manuca][])
34
+ * [BUGFIX: Update README.md to better document this `ten_years_rails` fork](https://github.com/fastruby/next_rails/pull/11)
35
+ * [BUGFIX: Make ActionView an optional dependency](https://github.com/fastruby/next_rails/pull/6)
7
36
 
8
37
  # v1.0.2 / 2020-01-20
9
38
 
@@ -11,4 +40,4 @@
11
40
 
12
41
  # v1.0.0 / 2019-07-24
13
42
 
14
- * Official Release
43
+ * Official Release
data/CODEOWNERS ADDED
@@ -0,0 +1,4 @@
1
+ # These code owners will be the default owners to everything in the repository.
2
+ # Unless a posterior rule has precedence, they will be automatically requested
3
+ # for review when a pull request is opened.
4
+ * @fastruby/black-bunny-brigade
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at oss@ombulabs.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/README.md CHANGED
@@ -34,6 +34,8 @@ bundle_report outdated | head -n 5
34
34
  # Show gems that don't work with Rails 5.2.0
35
35
  bundle_report compatibility --rails-version=5.2.0
36
36
  bundle_report --help
37
+ # Find minimum compatible ruby version with Rails 7.0.0
38
+ bundle_report ruby_check --rails-version=7.0.0
37
39
  ```
38
40
 
39
41
  ### Deprecation tracking
@@ -54,7 +56,20 @@ RSpec.configure do |config|
54
56
  end
55
57
  ```
56
58
 
57
- We don't use MiniTest, so there isn't a prebuilt config for it but I suspect it's pretty similar to `DeprecationTracker.track_rspec`.
59
+ If using minitest, add this somewhere close to the top of your `test_helper.rb`:
60
+
61
+ ```ruby
62
+ # Tracker deprecation messages in each file
63
+ if ENV["DEPRECATION_TRACKER"]
64
+ DeprecationTracker.track_minitest(
65
+ shitlist_path: "test/support/deprecation_warning.shitlist.json",
66
+ mode: ENV["DEPRECATION_TRACKER"],
67
+ transform_message: -> (message) { message.gsub("#{Rails.root}/", "") }
68
+ )
69
+ end
70
+ ```
71
+
72
+ > Keep in mind this is currently not compatible with the `minitest/parallel_fork` gem!
58
73
 
59
74
  Once you have that, you can start using deprecation tracking in your tests:
60
75
 
@@ -78,12 +93,21 @@ deprecations --help # For more options and examples
78
93
 
79
94
  Right now, the path to the shitlist is hardcoded so make sure you store yours at `spec/support/deprecations.shitlist.json`.
80
95
 
96
+ #### `next_rails` command
97
+
98
+ You can use `next_rails` to fetch the version of the gem installed.
99
+
100
+ ```bash
101
+ next_rails --version
102
+ next_rails --help # For more options and examples
103
+ ```
104
+
81
105
  ### Dual-boot Rails next
82
106
 
83
107
  This command helps you dual-boot your application.
84
108
 
85
109
  ```bash
86
- next --init # Create Gemfile.next
110
+ next --init # Create Gemfile.next and Gemfile.next.lock
87
111
  vim Gemfile # Tweak your dependencies conditionally using `next?`
88
112
  next bundle install # Install new gems
89
113
  next rails s # Start server using Gemfile.next
@@ -105,6 +129,17 @@ Or install it yourself as:
105
129
 
106
130
  $ gem install next_rails
107
131
 
132
+ ## Setup
133
+
134
+ Execute:
135
+
136
+ $ next --init
137
+
138
+ Init will create a Gemfile.next and an initialized Gemfile.next.lock.
139
+ The Gemfile.next.lock is initialized with the contents of your existing
140
+ Gemfile.lock lock file. We initialize the Gemfile.next.lock to prevent
141
+ major version jumps when running the next version of Rails.
142
+
108
143
  ## License
109
144
 
110
145
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/exe/bundle_report CHANGED
@@ -17,6 +17,12 @@ at_exit do
17
17
  Examples:
18
18
  #{$0} compatibility --rails-version 5.0
19
19
  #{$0} outdated
20
+
21
+ ruby_check To find a compatible ruby version for the target rails version
22
+
23
+ Examples:
24
+ #{$0} ruby_check --rails-version 7.0.0
25
+
20
26
  EOS
21
27
 
22
28
  opts.separator ""
@@ -47,6 +53,7 @@ at_exit do
47
53
  report_type = ARGV.first
48
54
 
49
55
  case report_type
56
+ when "ruby_check" then NextRails::BundleReport.compatible_ruby_version(rails_version: options.fetch(:rails_version))
50
57
  when "outdated" then NextRails::BundleReport.outdated
51
58
  else
52
59
  NextRails::BundleReport.compatibility(rails_version: options.fetch(:rails_version, "5.0"), include_rails_gems: options.fetch(:include_rails_gems, false))
data/exe/next.sh CHANGED
@@ -10,6 +10,13 @@ STRING
10
10
  mv Gemfile.tmp Gemfile
11
11
 
12
12
  ln -s Gemfile Gemfile.next
13
+
14
+ # Initialize the Gemfile.next.lock
15
+ # Prevents major version jumps when we start without a Gemfile.next.lock
16
+ if [ -f "Gemfile.lock" ] && [ ! -f "Gemfile.next.lock" ]; then
17
+ cp Gemfile.lock Gemfile.next.lock
18
+ fi
19
+
13
20
  echo <<-MESSAGE
14
21
  Created Gemfile.next (a symlink to your Gemfile). Your Gemfile has been modified to support dual-booting!
15
22
 
data/exe/next_rails ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require "optparse"
3
+ require "next_rails/version"
4
+
5
+ options = {}
6
+ option_parser = OptionParser.new do |opts|
7
+ opts.banner = <<-MESSAGE
8
+ Usage: #{__FILE__.to_s} [options]
9
+
10
+ Examples:
11
+ bin/next_rails --version info # Show the version of the gem installed
12
+ MESSAGE
13
+
14
+ opts.on("--version", "show version of the gem") do
15
+ options[:version] = true
16
+ end
17
+
18
+ opts.on_tail("-h", "--help", "Prints this help") do
19
+ puts opts
20
+ exit
21
+ end
22
+ end
23
+
24
+ option_parser.parse!
25
+
26
+ if options.fetch(:version, false)
27
+ puts NextRails::VERSION
28
+ exit 2
29
+ end
@@ -27,6 +27,25 @@ class DeprecationTracker
27
27
  end
28
28
  end
29
29
 
30
+ module MinitestExtension
31
+ def self.new(deprecation_tracker)
32
+ @@deprecation_tracker = deprecation_tracker
33
+
34
+ Module.new do
35
+ def before_setup
36
+ test_file_name = method(name).source_location.first.to_s
37
+ @@deprecation_tracker.bucket = test_file_name.gsub(Rails.root.to_s, ".")
38
+ super
39
+ end
40
+
41
+ def after_teardown
42
+ super
43
+ @@deprecation_tracker.bucket = nil
44
+ end
45
+ end
46
+ end
47
+ end
48
+
30
49
  # There are two forms of the `warn` method: one for class Kernel and one for instances of Kernel (i.e., every Object)
31
50
  Object.prepend(KernelWarnTracker)
32
51
 
@@ -39,16 +58,24 @@ class DeprecationTracker
39
58
  end
40
59
  end
41
60
 
42
- def self.track_rspec(rspec_config, opts = {})
61
+ def self.init_tracker(opts = {})
43
62
  shitlist_path = opts[:shitlist_path]
44
63
  mode = opts[:mode]
45
64
  transform_message = opts[:transform_message]
46
- deprecation_tracker = DeprecationTracker.new(shitlist_path, transform_message)
65
+ deprecation_tracker = DeprecationTracker.new(shitlist_path, transform_message, mode)
47
66
  if defined?(ActiveSupport)
48
- ActiveSupport::Deprecation.behavior << -> (message, _callstack, _deprecation_horizon, _gem_name) { deprecation_tracker.add(message) }
67
+ ActiveSupport::Deprecation.behavior << -> (message, _callstack = nil, _deprecation_horizon = nil, _gem_name = nil) {
68
+ deprecation_tracker.add(message)
69
+ }
49
70
  end
50
71
  KernelWarnTracker.callbacks << -> (message) { deprecation_tracker.add(message) }
51
72
 
73
+ deprecation_tracker
74
+ end
75
+
76
+ def self.track_rspec(rspec_config, opts = {})
77
+ deprecation_tracker = init_tracker(opts)
78
+
52
79
  rspec_config.around do |example|
53
80
  deprecation_tracker.bucket = example.metadata.fetch(:rerun_file_path)
54
81
 
@@ -60,21 +87,27 @@ class DeprecationTracker
60
87
  end
61
88
 
62
89
  rspec_config.after(:suite) do
63
- if mode == "save"
64
- deprecation_tracker.save
65
- elsif mode == "compare"
66
- deprecation_tracker.compare
67
- end
90
+ deprecation_tracker.after_run
68
91
  end
69
92
  end
70
93
 
71
- attr_reader :deprecation_messages, :shitlist_path, :transform_message
72
- attr_reader :bucket
94
+ def self.track_minitest(opts = {})
95
+ tracker = init_tracker(opts)
73
96
 
74
- def initialize(shitlist_path, transform_message = nil)
97
+ Minitest.after_run do
98
+ tracker.after_run
99
+ end
100
+
101
+ ActiveSupport::TestCase.include(MinitestExtension.new(tracker))
102
+ end
103
+
104
+ attr_reader :deprecation_messages, :shitlist_path, :transform_message, :bucket, :mode
105
+
106
+ def initialize(shitlist_path, transform_message = nil, mode = :save)
75
107
  @shitlist_path = shitlist_path
76
108
  @transform_message = transform_message || -> (message) { message }
77
109
  @deprecation_messages = {}
110
+ @mode = mode.to_sym
78
111
  end
79
112
 
80
113
  def add(message)
@@ -88,6 +121,14 @@ class DeprecationTracker
88
121
  @deprecation_messages[value] ||= [] unless value.nil?
89
122
  end
90
123
 
124
+ def after_run
125
+ if mode == :save
126
+ save
127
+ elsif mode == :compare
128
+ compare
129
+ end
130
+ end
131
+
91
132
  def compare
92
133
  shitlist = read_shitlist
93
134
 
@@ -130,11 +171,19 @@ class DeprecationTracker
130
171
 
131
172
  def save
132
173
  new_shitlist = create_temp_shitlist
174
+ create_if_shitlist_path_does_not_exist
133
175
  FileUtils.cp(new_shitlist.path, shitlist_path)
134
176
  ensure
135
177
  new_shitlist.delete if new_shitlist
136
178
  end
137
179
 
180
+ def create_if_shitlist_path_does_not_exist
181
+ dirname = File.dirname(shitlist_path)
182
+ unless File.directory?(dirname)
183
+ FileUtils.mkdir_p(dirname)
184
+ end
185
+ end
186
+
138
187
  def create_temp_shitlist
139
188
  temp_file = Tempfile.new("temp-deprecation-tracker-shitlist")
140
189
  temp_file.write(JSON.pretty_generate(normalized_deprecation_messages))
@@ -2,28 +2,26 @@ require "colorize"
2
2
  require "cgi"
3
3
  require "erb"
4
4
  require "json"
5
+ require "net/http"
5
6
 
6
7
  module NextRails
7
8
  class BundleReport
8
9
  def self.compatibility(rails_version:, include_rails_gems:)
9
10
  incompatible_gems = NextRails::GemInfo.all.reject do |gem|
10
11
  gem.compatible_with_rails?(rails_version: rails_version) || (!include_rails_gems && gem.from_rails?)
11
- end.sort_by do |gem|
12
- [
13
- gem.latest_version.compatible_with_rails?(rails_version: rails_version) ? 0 : 1,
14
- gem.name
15
- ].join("-")
16
- end
12
+ end.sort_by { |gem| gem.name }
13
+
14
+ incompatible_gems.each { |gem| gem.find_latest_compatible(rails_version: rails_version) }
17
15
 
18
16
  incompatible_gems_by_state = incompatible_gems.group_by { |gem| gem.state(rails_version) }
19
17
 
20
18
  template = <<~ERB
21
- <% if incompatible_gems_by_state[:latest_compatible] -%>
19
+ <% if incompatible_gems_by_state[:found_compatible] -%>
22
20
  <%= "=> Incompatible with Rails #{rails_version} (with new versions that are compatible):".white.bold %>
23
21
  <%= "These gems will need to be upgraded before upgrading to Rails #{rails_version}.".italic %>
24
22
 
25
- <% incompatible_gems_by_state[:latest_compatible].each do |gem| -%>
26
- <%= gem_header(gem) %> - upgrade to <%= gem.latest_version.version %>
23
+ <% incompatible_gems_by_state[:found_compatible].each do |gem| -%>
24
+ <%= gem_header(gem) %> - upgrade to <%= gem.latest_compatible_version.version %>
27
25
  <% end -%>
28
26
 
29
27
  <% end -%>
@@ -58,6 +56,45 @@ module NextRails
58
56
  header
59
57
  end
60
58
 
59
+ def self.compatible_ruby_version(rails_version)
60
+ # find all the versions of rails gem
61
+ uri = URI('https://rubygems.org/api/v1/versions/rails.json')
62
+ res = Net::HTTP.get_response(uri)
63
+ all_versions_res = JSON.parse(res.body)
64
+
65
+ # push all the versions in an array
66
+ all_versions = []
67
+ all_versions_res.each { |rv| all_versions << rv['number'] }
68
+
69
+ rv = rails_version[:rails_version]
70
+ matched_versions = all_versions.select { |h| h.start_with?(rv) }
71
+
72
+ # the list can either have the exact version or the latest version in the series of versions
73
+ # you are looking at
74
+ # ex: matched_versions = ["6.1.4.2", "6.1.4.1", "6.1.4"]
75
+ # if you have passed "6.1.4" and the list has the exact version, it will match and send
76
+ # the ruby version for it bu tif you had passed "6.1", then it will look for the
77
+ # latest version matching "6.1" which is "6.1.4.2" in this case and will return ruby
78
+ # version for it.
79
+ exact_version = matched_versions.include?(rv) ? rv : matched_versions[0]
80
+
81
+ if exact_version
82
+ uri = URI("https://rubygems.org/api/v2/rubygems/rails/versions/#{exact_version}.json")
83
+ res = Net::HTTP.get_response(uri)
84
+ ruby_version = JSON.parse(res.body)["ruby_version"]
85
+ else
86
+ ruby_version = nil
87
+ end
88
+
89
+
90
+ if ruby_version
91
+ puts "The required ruby version is #{ruby_version} for matched rails version #{exact_version}"
92
+ ruby_version
93
+ else
94
+ puts "Could not find a compatible ruby version"
95
+ end
96
+ end
97
+
61
98
  def self.outdated
62
99
  gems = NextRails::GemInfo.all
63
100
  out_of_date_gems = gems.reject(&:up_to_date?).sort_by(&:created_at)
@@ -1,15 +1,5 @@
1
- begin
2
- require "action_view"
3
- rescue LoadError
4
- puts "ActionView not available"
5
- end
6
-
7
1
  module NextRails
8
2
  class GemInfo
9
- if defined?(ActionView)
10
- include ActionView::Helpers::DateHelper
11
- end
12
-
13
3
  class NullGemInfo < GemInfo
14
4
  def initialize; end
15
5
 
@@ -38,13 +28,28 @@ module NextRails
38
28
  end
39
29
  end
40
30
 
31
+ RAILS_GEMS = [
32
+ "rails",
33
+ "activemodel",
34
+ "activerecord",
35
+ "actionmailer",
36
+ "actioncable",
37
+ "actionpack",
38
+ "actionview",
39
+ "activejob",
40
+ "activestorage",
41
+ "activesupport",
42
+ "railties",
43
+ ].freeze
44
+
41
45
  def self.all
42
46
  Gem::Specification.each.map do |gem_specification|
43
47
  new(gem_specification)
44
48
  end
45
49
  end
46
50
 
47
- attr_reader :gem_specification, :version, :name
51
+ attr_reader :gem_specification, :version, :name, :latest_compatible_version
52
+
48
53
  def initialize(gem_specification)
49
54
  @gem_specification = gem_specification
50
55
  @version = gem_specification.version
@@ -52,11 +57,7 @@ module NextRails
52
57
  end
53
58
 
54
59
  def age
55
- if respond_to?(:time_ago_in_words)
56
- "#{time_ago_in_words(created_at)} ago"
57
- else
58
- created_at.strftime("%b %e, %Y")
59
- end
60
+ created_at.strftime("%b %e, %Y")
60
61
  end
61
62
 
62
63
  def sourced_from_git?
@@ -71,59 +72,69 @@ module NextRails
71
72
  version == latest_version.version
72
73
  end
73
74
 
75
+ def from_rails?
76
+ RAILS_GEMS.include?(name)
77
+ end
78
+
74
79
  def state(rails_version)
75
80
  if compatible_with_rails?(rails_version: rails_version)
76
81
  :compatible
77
- elsif latest_version.compatible_with_rails?(rails_version: rails_version)
78
- :latest_compatible
79
- elsif latest_version.version == "NOT FOUND"
82
+ elsif latest_compatible_version.version == "NOT FOUND"
80
83
  :no_new_version
84
+ elsif latest_compatible_version
85
+ :found_compatible
81
86
  else
82
87
  :incompatible
83
88
  end
84
89
  end
85
90
 
86
- def latest_version
87
- @latest_version ||= begin
88
- latest_gem_specification = Gem.latest_spec_for(name)
89
- if latest_gem_specification
90
- GemInfo.new(latest_gem_specification)
91
- else
92
- NullGemInfo.new
93
- end
94
- end
95
- end
96
-
97
- def compatible_with_rails?(rails_version: Gem::Version.new("5.0"))
91
+ def compatible_with_rails?(rails_version:)
98
92
  unsatisfied_rails_dependencies(rails_version: rails_version).empty?
99
93
  end
100
94
 
101
95
  def unsatisfied_rails_dependencies(rails_version:)
102
- rails_dependencies = gem_specification.runtime_dependencies.select {|dependency| rails_gems.include?(dependency.name) }
96
+ spec_compatible_with_rails?(specification: gem_specification, rails_version: rails_version)
97
+ end
103
98
 
104
- rails_dependencies.reject do |rails_dependency|
105
- rails_dependency.requirement.satisfied_by?(Gem::Version.new(rails_version))
99
+ def find_latest_compatible(rails_version:)
100
+ dependency = Gem::Dependency.new(@name)
101
+ fetcher = Gem::SpecFetcher.new
102
+
103
+ # list all available data for released gems
104
+ list, errors = fetcher.available_specs(:released)
105
+
106
+ specs = []
107
+ # filter only specs for the current gem and older versions
108
+ list.each do |source, gem_tuples|
109
+ gem_tuples.each do |gem_tuple|
110
+ if gem_tuple.name == @name && gem_tuple.version > @version
111
+ specs << source.fetch_spec(gem_tuple)
112
+ end
113
+ end
106
114
  end
107
- end
108
115
 
109
- def from_rails?
110
- rails_gems.include?(name)
116
+ # if nothing is found, consider gem incompatible
117
+ if specs.empty?
118
+ @latest_compatible_version = NullGemInfo.new
119
+ return
120
+ end
121
+
122
+ # if specs are found, look for the first one from that is compatible
123
+ # with the desired rails version starting from the end
124
+ specs.reverse.each do |spec|
125
+ if spec_compatible_with_rails?(specification: spec, rails_version: rails_version).empty?
126
+ @latest_compatible_version = spec
127
+ break
128
+ end
129
+ end
111
130
  end
112
131
 
113
- private def rails_gems
114
- [
115
- "rails",
116
- "activemodel",
117
- "activerecord",
118
- "actionmailer",
119
- "actioncable",
120
- "actionpack",
121
- "actionview",
122
- "activejob",
123
- "activestorage",
124
- "activesupport",
125
- "railties",
126
- ]
132
+ def spec_compatible_with_rails?(specification:, rails_version:)
133
+ rails_dependencies = specification.runtime_dependencies.select {|dependency| RAILS_GEMS.include?(dependency.name) }
134
+
135
+ rails_dependencies.reject do |rails_dependency|
136
+ rails_dependency.requirement.satisfied_by?(Gem::Version.new(rails_version))
137
+ end
127
138
  end
128
139
  end
129
140
  end
@@ -1,3 +1,3 @@
1
1
  module NextRails
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
data/next_rails.gemspec CHANGED
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "colorize", ">= 0.8.1"
27
- spec.add_development_dependency "bundler", "~> 1.16"
28
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "bundler", ">= 1.16", "< 3.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "simplecov", "~> 0.17.1"
31
31
  spec.add_development_dependency "timecop", "~> 0.9.1"
32
- spec.add_development_dependency "actionview", "< 6.0"
32
+ spec.add_development_dependency "webmock"
33
33
  end
@@ -0,0 +1,9 @@
1
+ **IMPORTANT**: Please read the README before submitting pull requests for this project. Additionally, if your PR closes any open GitHub issues, make sure you include Closes #XXXX in your comment or use the option on the PR's sidebar to add related issues to auto-close the issue that your PR fixes.
2
+
3
+ - [ ] Add an entry to `CHANGELOG.md` that links to this PR under the "main (unreleased)" heading.
4
+
5
+ Description:
6
+
7
+ Please include a summary of the change and which issue is fixed or which feature is introduced. If changes to the behavior are made, clearly describe what changes.
8
+
9
+ I will abide by the [code of conduct](https://github.com/fastruby/next_rails/blob/main/CODE_OF_CONDUCT.md).
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: next_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Tagwerker
8
8
  - Luis Sagastume
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-04-06 00:00:00.000000000 Z
12
+ date: 2022-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -29,30 +29,36 @@ dependencies:
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.16'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
35
38
  type: :development
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - "~>"
42
+ - - ">="
40
43
  - !ruby/object:Gem::Version
41
44
  version: '1.16'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: rake
44
50
  requirement: !ruby/object:Gem::Requirement
45
51
  requirements:
46
52
  - - "~>"
47
53
  - !ruby/object:Gem::Version
48
- version: '10.0'
54
+ version: '13.0'
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
59
  - - "~>"
54
60
  - !ruby/object:Gem::Version
55
- version: '10.0'
61
+ version: '13.0'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: rspec
58
64
  requirement: !ruby/object:Gem::Requirement
@@ -96,19 +102,19 @@ dependencies:
96
102
  - !ruby/object:Gem::Version
97
103
  version: 0.9.1
98
104
  - !ruby/object:Gem::Dependency
99
- name: actionview
105
+ name: webmock
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
- - - "<"
108
+ - - ">="
103
109
  - !ruby/object:Gem::Version
104
- version: '6.0'
110
+ version: '0'
105
111
  type: :development
106
112
  prerelease: false
107
113
  version_requirements: !ruby/object:Gem::Requirement
108
114
  requirements:
109
- - - "<"
115
+ - - ">="
110
116
  - !ruby/object:Gem::Version
111
- version: '6.0'
117
+ version: '0'
112
118
  description: A set of handy tools to upgrade your Rails application and keep it up
113
119
  to date
114
120
  email:
@@ -120,13 +126,20 @@ executables:
120
126
  - gem-next-diff
121
127
  - next
122
128
  - next.sh
129
+ - next_rails
123
130
  extensions: []
124
131
  extra_rdoc_files: []
125
132
  files:
133
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
134
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
135
+ - ".github/dependabot.yml"
136
+ - ".github/workflows/main.yml"
126
137
  - ".gitignore"
127
138
  - ".rspec"
128
139
  - ".travis.yml"
129
140
  - CHANGELOG.md
141
+ - CODEOWNERS
142
+ - CODE_OF_CONDUCT.md
130
143
  - Gemfile
131
144
  - LICENSE.txt
132
145
  - README.md
@@ -139,17 +152,19 @@ files:
139
152
  - exe/gem-next-diff
140
153
  - exe/next
141
154
  - exe/next.sh
155
+ - exe/next_rails
142
156
  - lib/deprecation_tracker.rb
143
157
  - lib/next_rails.rb
144
158
  - lib/next_rails/bundle_report.rb
145
159
  - lib/next_rails/gem_info.rb
146
160
  - lib/next_rails/version.rb
147
161
  - next_rails.gemspec
162
+ - pull_request_template.md
148
163
  homepage: https://github.com/fastruby/next_rails
149
164
  licenses:
150
165
  - MIT
151
166
  metadata: {}
152
- post_install_message:
167
+ post_install_message:
153
168
  rdoc_options: []
154
169
  require_paths:
155
170
  - lib
@@ -164,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
179
  - !ruby/object:Gem::Version
165
180
  version: '0'
166
181
  requirements: []
167
- rubygems_version: 3.0.8
168
- signing_key:
182
+ rubygems_version: 3.1.6
183
+ signing_key:
169
184
  specification_version: 4
170
185
  summary: A toolkit to upgrade your next Rails application
171
186
  test_files: []