From 34ca63d3baf0789db99a16538d44eed270af54c0 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Fri, 9 Feb 2024 15:01:20 -0300 Subject: [PATCH] Subscribe to rails deprecations (#242) Subscribe to rails deprecations so DepShield is informed whenever the notification behavior is set to `:notify`. --- packages/dep_shield/CHANGELOG.md | 12 ++++++++++++ packages/dep_shield/Gemfile | 4 +--- packages/dep_shield/Gemfile.lock | 7 ++++--- packages/dep_shield/dep_shield.gemspec | 10 +++++----- .../dep_shield/gemfiles/rails_6_0.gemfile.lock | 7 +++++-- .../dep_shield/gemfiles/rails_6_1.gemfile.lock | 7 +++++-- .../dep_shield/gemfiles/rails_7_0.gemfile.lock | 7 +++++-- packages/dep_shield/lib/dep_shield/railtie.rb | 17 +++++++++++++++++ packages/dep_shield/lib/dep_shield/version.rb | 2 +- .../dep_shield/spec/dep_shield/railtie_spec.rb | 18 ++++++++++++++++++ packages/dep_shield/spec/spec_helper.rb | 2 +- 11 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 packages/dep_shield/lib/dep_shield/railtie.rb create mode 100644 packages/dep_shield/spec/dep_shield/railtie_spec.rb diff --git a/packages/dep_shield/CHANGELOG.md b/packages/dep_shield/CHANGELOG.md index e674c431..5a0ac9a5 100644 --- a/packages/dep_shield/CHANGELOG.md +++ b/packages/dep_shield/CHANGELOG.md @@ -1,5 +1,17 @@ ## [Unreleased] +## [0.3.0] + +- Subscribe to deprecation.rails notifications from railtie + +## [0.2.0] + +- Dynamically load todo lists + +## [0.1.1] + +- Fixes / navigates around different returns for YAML.load_file + ## [0.1.0] - 2024-01-17 - Initial release diff --git a/packages/dep_shield/Gemfile b/packages/dep_shield/Gemfile index 6536685d..b6b024fe 100644 --- a/packages/dep_shield/Gemfile +++ b/packages/dep_shield/Gemfile @@ -6,9 +6,7 @@ source "https://rubygems.org" gemspec gem "nokogiri", "< 1.16" - +gem "rails", "<= 7.0.6" gem "rake", "~> 13.0" - gem "rspec", "~> 3.0" - gem "rubocop-powerhome", path: "../rubocop-powerhome" diff --git a/packages/dep_shield/Gemfile.lock b/packages/dep_shield/Gemfile.lock index 3d4ddd19..4d4ebfd8 100644 --- a/packages/dep_shield/Gemfile.lock +++ b/packages/dep_shield/Gemfile.lock @@ -11,9 +11,9 @@ PATH PATH remote: . specs: - dep_shield (0.2.1) + dep_shield (0.3.0) nitro_config - rails (>= 6.0.6.1, <= 7.0.6) + railties (>= 6.0.6.1, <= 7.0.6) sentry-rails (= 5.5.0) sentry-ruby (= 5.5.0) @@ -119,7 +119,7 @@ GEM mini_mime (1.1.5) mini_portile2 (2.8.5) minitest (5.21.1) - net-imap (0.4.9.1) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) @@ -266,6 +266,7 @@ DEPENDENCIES dep_shield! license_finder (>= 7.0) nokogiri (< 1.16) + rails (<= 7.0.6) rake (~> 13.0) rspec (~> 3.0) rspec-rails (~> 5.1.2) diff --git a/packages/dep_shield/dep_shield.gemspec b/packages/dep_shield/dep_shield.gemspec index 7f811233..6e075354 100644 --- a/packages/dep_shield/dep_shield.gemspec +++ b/packages/dep_shield/dep_shield.gemspec @@ -31,15 +31,15 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] + spec.add_dependency "nitro_config" + spec.add_dependency "railties", ">= 6.0.6.1", "<= 7.0.6" + spec.add_dependency "sentry-rails", "5.5.0" + spec.add_dependency "sentry-ruby", "5.5.0" + spec.add_development_dependency "appraisal", "~> 2.5.0" spec.add_development_dependency "combustion", "~> 1.4" spec.add_development_dependency "license_finder", ">= 7.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rspec-rails", "~> 5.1.2" spec.add_development_dependency "sqlite3", "~> 1.4.2" - - spec.add_dependency "nitro_config" - spec.add_dependency "rails", ">= 6.0.6.1", "<= 7.0.6" - spec.add_dependency "sentry-rails", "5.5.0" - spec.add_dependency "sentry-ruby", "5.5.0" end diff --git a/packages/dep_shield/gemfiles/rails_6_0.gemfile.lock b/packages/dep_shield/gemfiles/rails_6_0.gemfile.lock index 0bf432d1..70d0ae36 100644 --- a/packages/dep_shield/gemfiles/rails_6_0.gemfile.lock +++ b/packages/dep_shield/gemfiles/rails_6_0.gemfile.lock @@ -11,9 +11,9 @@ PATH PATH remote: .. specs: - dep_shield (0.2.1) + dep_shield (0.3.0) nitro_config - rails (>= 6.0.6.1, <= 7.0.6) + railties (>= 6.0.6.1, <= 7.0.6) sentry-rails (= 5.5.0) sentry-ruby (= 5.5.0) @@ -128,6 +128,8 @@ GEM activesupport (>= 5.2.8.1) nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) + nokogiri (1.15.5-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -251,6 +253,7 @@ GEM PLATFORMS arm64-darwin + x86_64-linux DEPENDENCIES appraisal (~> 2.5.0) diff --git a/packages/dep_shield/gemfiles/rails_6_1.gemfile.lock b/packages/dep_shield/gemfiles/rails_6_1.gemfile.lock index dadd9937..1e7046a7 100644 --- a/packages/dep_shield/gemfiles/rails_6_1.gemfile.lock +++ b/packages/dep_shield/gemfiles/rails_6_1.gemfile.lock @@ -11,9 +11,9 @@ PATH PATH remote: .. specs: - dep_shield (0.2.1) + dep_shield (0.3.0) nitro_config - rails (>= 6.0.6.1, <= 7.0.6) + railties (>= 6.0.6.1, <= 7.0.6) sentry-rails (= 5.5.0) sentry-ruby (= 5.5.0) @@ -132,6 +132,8 @@ GEM activesupport (>= 5.2.8.1) nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) + nokogiri (1.15.5-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -254,6 +256,7 @@ GEM PLATFORMS arm64-darwin + x86_64-linux DEPENDENCIES appraisal (~> 2.5.0) diff --git a/packages/dep_shield/gemfiles/rails_7_0.gemfile.lock b/packages/dep_shield/gemfiles/rails_7_0.gemfile.lock index 37a153e0..a2822adf 100644 --- a/packages/dep_shield/gemfiles/rails_7_0.gemfile.lock +++ b/packages/dep_shield/gemfiles/rails_7_0.gemfile.lock @@ -11,9 +11,9 @@ PATH PATH remote: .. specs: - dep_shield (0.2.1) + dep_shield (0.3.0) nitro_config - rails (>= 6.0.6.1, <= 7.0.6) + railties (>= 6.0.6.1, <= 7.0.6) sentry-rails (= 5.5.0) sentry-ruby (= 5.5.0) @@ -138,6 +138,8 @@ GEM activesupport (>= 5.2.8.1) nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) + nokogiri (1.15.5-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -253,6 +255,7 @@ GEM PLATFORMS arm64-darwin + x86_64-linux DEPENDENCIES appraisal (~> 2.5.0) diff --git a/packages/dep_shield/lib/dep_shield/railtie.rb b/packages/dep_shield/lib/dep_shield/railtie.rb new file mode 100644 index 00000000..685050a8 --- /dev/null +++ b/packages/dep_shield/lib/dep_shield/railtie.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "dep_shield" + +module DepShield + # Ties DepShield to rails deprecations system + class Railtie < Rails::Railtie + initializer "dep_shield.subscribe" do + ActiveSupport::Notifications.subscribe("deprecation.rails") do |name, _start, _finish, _id, payload| + message = payload[:message] || "this is deprecated in rails" + callstack = payload[:callstack] || caller + + DepShield.raise_or_capture!(name: name, message: message, callstack: callstack) + end + end + end +end diff --git a/packages/dep_shield/lib/dep_shield/version.rb b/packages/dep_shield/lib/dep_shield/version.rb index 9b4c3dab..950b8e05 100644 --- a/packages/dep_shield/lib/dep_shield/version.rb +++ b/packages/dep_shield/lib/dep_shield/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DepShield - VERSION = "0.2.1" + VERSION = "0.3.0" end diff --git a/packages/dep_shield/spec/dep_shield/railtie_spec.rb b/packages/dep_shield/spec/dep_shield/railtie_spec.rb new file mode 100644 index 00000000..4d505c27 --- /dev/null +++ b/packages/dep_shield/spec/dep_shield/railtie_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe DepShield::Deprecation do + it "subscribes to deprecation.rails" do + expect(DepShield).to( + receive(:raise_or_capture!) + .with(name: "deprecation.rails", message: "This has been so deprecated", callstack: ["file1.rb", "file2.rb"]) + ) + + ActiveSupport::Notifications.instrument( + "deprecation.rails", + message: "This has been so deprecated", + callstack: ["file1.rb", "file2.rb"] + ) + end +end diff --git a/packages/dep_shield/spec/spec_helper.rb b/packages/dep_shield/spec/spec_helper.rb index c0091cef..d21e3ad5 100644 --- a/packages/dep_shield/spec/spec_helper.rb +++ b/packages/dep_shield/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "bundler" -require "dep_shield" +require "dep_shield/railtie" require "rspec/rails" Bundler.require :default, :development