Skip to content

Commit

Permalink
Add rake task to check the upgrade for orphaned overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
lgebhardt committed Feb 25, 2019
1 parent 924f5c5 commit dd31121
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/jsonapi-resources.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'jsonapi/resources/railtie'
require 'jsonapi/naive_cache'
require 'jsonapi/compiled_json'
require 'jsonapi/resource'
Expand Down
9 changes: 9 additions & 0 deletions lib/jsonapi/resources/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module JSONAPI
module Resources
class Railtie < Rails::Railtie
rake_tasks do
load 'tasks/check_upgrade.rake'
end
end
end
end
52 changes: 52 additions & 0 deletions lib/tasks/check_upgrade.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'rake'
require 'jsonapi-resources'

namespace :jsonapi do
namespace :resources do
desc 'Checks application for orphaned overrides'
task :check_upgrade => :environment do
Rails.application.eager_load!

resource_klasses = ObjectSpace.each_object(Class).select { |klass| klass < JSONAPI::Resource}

puts "Checking #{resource_klasses.count} resources"

issues_found = 0

klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:find_records) }
unless klasses_with_deprecated.empty?
puts " Found the following resources the still implement `find_records`:"
klasses_with_deprecated.each { |klass| puts " #{klass}"}
puts " The `find_records` method is no longer called by JR. Please review and ensure your functionality is ported over."

issues_found = issues_found + klasses_with_deprecated.length
end

klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:records_for) }
unless klasses_with_deprecated.empty?
puts " Found the following resources the still implement `records_for`:"
klasses_with_deprecated.each { |klass| puts " #{klass}"}
puts " The `records_for` method is no longer called by JR. Please review and ensure your functionality is ported over."

issues_found = issues_found + klasses_with_deprecated.length
end

klasses_with_deprecated = resource_klasses.select { |klass| klass.methods.include?(:apply_includes) }
unless klasses_with_deprecated.empty?
puts " Found the following resources the still implement `apply_includes`:"
klasses_with_deprecated.each { |klass| puts " #{klass}"}
puts " The `apply_includes` method is no longer called by JR. Please review and ensure your functionality is ported over."

issues_found = issues_found + klasses_with_deprecated.length
end

if issues_found > 0
puts "Finished inspection. #{issues_found} issues found that may impact upgrading. Please address these issues. "
else
puts "Finished inspection with no issues found. Note this is only a cursory check for method overrides that will no \n" \
"longer be called by JSONAPI::Resources. This check in no way assures your code will continue to function as \n" \
"it did before the upgrade. Please do adequate testing before using in production."
end
end
end
end

0 comments on commit dd31121

Please sign in to comment.