Skip to content

Commit

Permalink
Subscribe to rails deprecations (#242)
Browse files Browse the repository at this point in the history
Subscribe to rails deprecations so DepShield is informed whenever the
notification behavior is set to `:notify`.
  • Loading branch information
xjunior authored Feb 9, 2024
1 parent 1ff3b89 commit 34ca63d
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 19 deletions.
12 changes: 12 additions & 0 deletions packages/dep_shield/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions packages/dep_shield/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 4 additions & 3 deletions packages/dep_shield/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions packages/dep_shield/dep_shield.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions packages/dep_shield/gemfiles/rails_6_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -251,6 +253,7 @@ GEM

PLATFORMS
arm64-darwin
x86_64-linux

DEPENDENCIES
appraisal (~> 2.5.0)
Expand Down
7 changes: 5 additions & 2 deletions packages/dep_shield/gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -254,6 +256,7 @@ GEM

PLATFORMS
arm64-darwin
x86_64-linux

DEPENDENCIES
appraisal (~> 2.5.0)
Expand Down
7 changes: 5 additions & 2 deletions packages/dep_shield/gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -253,6 +255,7 @@ GEM

PLATFORMS
arm64-darwin
x86_64-linux

DEPENDENCIES
appraisal (~> 2.5.0)
Expand Down
17 changes: 17 additions & 0 deletions packages/dep_shield/lib/dep_shield/railtie.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/dep_shield/lib/dep_shield/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DepShield
VERSION = "0.2.1"
VERSION = "0.3.0"
end
18 changes: 18 additions & 0 deletions packages/dep_shield/spec/dep_shield/railtie_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/dep_shield/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "bundler"
require "dep_shield"
require "dep_shield/railtie"
require "rspec/rails"

Bundler.require :default, :development
Expand Down

0 comments on commit 34ca63d

Please sign in to comment.