|
| 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