Skip to content

Commit dd31121

Browse files
committed
Add rake task to check the upgrade for orphaned overrides
1 parent 924f5c5 commit dd31121

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

lib/jsonapi-resources.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'jsonapi/resources/railtie'
12
require 'jsonapi/naive_cache'
23
require 'jsonapi/compiled_json'
34
require 'jsonapi/resource'

lib/jsonapi/resources/railtie.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module JSONAPI
2+
module Resources
3+
class Railtie < Rails::Railtie
4+
rake_tasks do
5+
load 'tasks/check_upgrade.rake'
6+
end
7+
end
8+
end
9+
end

lib/tasks/check_upgrade.rake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'rake'
2+
require 'jsonapi-resources'
3+
4+
namespace :jsonapi do
5+
namespace :resources do
6+
desc 'Checks application for orphaned overrides'
7+
task :check_upgrade => :environment do
8+
Rails.application.eager_load!
9+
10+
resource_klasses = ObjectSpace.each_object(Class).select { |klass| klass < JSONAPI::Resource}
11+
12+
puts "Checking #{resource_klasses.count} resources"
13+
14+
issues_found = 0
15+
16+
klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:find_records) }
17+
unless klasses_with_deprecated.empty?
18+
puts " Found the following resources the still implement `find_records`:"
19+
klasses_with_deprecated.each { |klass| puts " #{klass}"}
20+
puts " The `find_records` method is no longer called by JR. Please review and ensure your functionality is ported over."
21+
22+
issues_found = issues_found + klasses_with_deprecated.length
23+
end
24+
25+
klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:records_for) }
26+
unless klasses_with_deprecated.empty?
27+
puts " Found the following resources the still implement `records_for`:"
28+
klasses_with_deprecated.each { |klass| puts " #{klass}"}
29+
puts " The `records_for` method is no longer called by JR. Please review and ensure your functionality is ported over."
30+
31+
issues_found = issues_found + klasses_with_deprecated.length
32+
end
33+
34+
klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:apply_includes) }
35+
unless klasses_with_deprecated.empty?
36+
puts " Found the following resources the still implement `apply_includes`:"
37+
klasses_with_deprecated.each { |klass| puts " #{klass}"}
38+
puts " The `apply_includes` method is no longer called by JR. Please review and ensure your functionality is ported over."
39+
40+
issues_found = issues_found + klasses_with_deprecated.length
41+
end
42+
43+
if issues_found > 0
44+
puts "Finished inspection. #{issues_found} issues found that may impact upgrading. Please address these issues. "
45+
else
46+
puts "Finished inspection with no issues found. Note this is only a cursory check for method overrides that will no \n" \
47+
"longer be called by JSONAPI::Resources. This check in no way assures your code will continue to function as \n" \
48+
"it did before the upgrade. Please do adequate testing before using in production."
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)