warning_signs 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +8 -8
- data/README.md +105 -10
- data/lib/warning_signs/behavior/base.rb +28 -0
- data/lib/warning_signs/behavior/ignore.rb +9 -0
- data/lib/warning_signs/behavior/log.rb +9 -0
- data/lib/warning_signs/behavior/raise.rb +16 -0
- data/lib/warning_signs/behavior/stderr.rb +11 -0
- data/lib/warning_signs/behavior/stdout.rb +11 -0
- data/lib/warning_signs/caller_helper.rb +20 -0
- data/lib/warning_signs/deprecation.rb +14 -11
- data/lib/warning_signs/handler.rb +28 -24
- data/lib/warning_signs/message_formatter/base.rb +39 -0
- data/lib/warning_signs/message_formatter/hash.rb +12 -0
- data/lib/warning_signs/message_formatter/json.rb +12 -0
- data/lib/warning_signs/message_formatter/text.rb +9 -0
- data/lib/warning_signs/message_formatter/yaml.rb +12 -0
- data/lib/warning_signs/message_formatter_list.rb +25 -0
- data/lib/warning_signs/only_except.rb +32 -0
- data/lib/warning_signs/rails_deprecation_catcher.rb +5 -1
- data/lib/warning_signs/ruby_deprecation_catcher.rb +5 -11
- data/lib/warning_signs/version.rb +1 -1
- data/lib/warning_signs.rb +1 -0
- data/warning_signs.gemspec +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52cb05e7b564245d88a8ef7906fce215c31ebe482cdaaee537d738004f8c35c8
|
4
|
+
data.tar.gz: e8ad757904f8c87f2a5afe3c486873ffb4b955cd711be81a6021390284c35691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41cc8a65c3e4b37dab7904d8537459ae84f0badfc00b013cf15c888fc072c913e69963bf663e1c9a735274e1029b01f0fc782a4b76f1d98b693a333556667e0f
|
7
|
+
data.tar.gz: 33d9f42ca6d9dabf5e8501805b4db5cc62b54a4264b542d5f2fa110b2b7df3edc6fbcafcaa89e1c7b4828515cfdae4c745154df0002e3f8880757d26a056683c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 0.6.0
|
2
|
+
|
3
|
+
* Allow for format options in messages
|
4
|
+
* Allow for filter options in backtrace
|
5
|
+
* Allow for multiple output behaviors based on environment
|
6
|
+
|
7
|
+
## 0.5.1
|
8
|
+
|
9
|
+
* Better filtering of backtraces
|
10
|
+
|
11
|
+
## 0.5.0
|
12
|
+
|
13
|
+
* Allow handlers to print out backtraces for log, stdout, and stderr behaviors
|
14
|
+
|
1
15
|
## 0.4.0
|
2
16
|
|
3
17
|
* Allow handlers to take into account Ruby warning categories
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
warning_signs (0.
|
4
|
+
warning_signs (0.6.0)
|
5
5
|
awesome_print
|
6
|
-
railties
|
6
|
+
railties (<= 7.1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -41,16 +41,16 @@ GEM
|
|
41
41
|
json (2.6.3)
|
42
42
|
language_server-protocol (3.17.0.3)
|
43
43
|
lint_roller (1.0.0)
|
44
|
-
loofah (2.
|
44
|
+
loofah (2.21.3)
|
45
45
|
crass (~> 1.0.2)
|
46
|
-
nokogiri (>= 1.
|
46
|
+
nokogiri (>= 1.12.0)
|
47
47
|
method_source (1.0.0)
|
48
48
|
minitest (5.18.0)
|
49
|
-
nokogiri (1.
|
49
|
+
nokogiri (1.15.0-arm64-darwin)
|
50
50
|
racc (~> 1.4)
|
51
|
-
nokogiri (1.
|
51
|
+
nokogiri (1.15.0-x86_64-darwin)
|
52
52
|
racc (~> 1.4)
|
53
|
-
nokogiri (1.
|
53
|
+
nokogiri (1.15.0-x86_64-linux)
|
54
54
|
racc (~> 1.4)
|
55
55
|
parallel (1.23.0)
|
56
56
|
parser (3.2.2.1)
|
@@ -130,7 +130,7 @@ GEM
|
|
130
130
|
standard-performance (1.0.1)
|
131
131
|
lint_roller (~> 1.0)
|
132
132
|
rubocop-performance (~> 1.16.0)
|
133
|
-
thor (1.2.
|
133
|
+
thor (1.2.2)
|
134
134
|
tzinfo (2.0.6)
|
135
135
|
concurrent-ruby (~> 1.0)
|
136
136
|
unicode-display_width (2.4.2)
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
The Warning Signs gem builds upon the ideas of the
|
4
4
|
[Ruby Warning Gem](https://github.com/jeremyevans/ruby-warning)
|
5
|
-
and [Stop
|
5
|
+
and [Stop ignoring your Rails (and Ruby) deprecations!](https://blog.testdouble.com/posts/2023-04-24-stop-ignoring-your-ruby-and-rails-deprecations/).
|
6
6
|
|
7
7
|
The idea is to provide an easily-configurable way to manage deprecation
|
8
|
-
warnings from Ruby and Rails to support your
|
8
|
+
warnings from Ruby and Rails to support your upgrades.
|
9
9
|
|
10
10
|
## Installing Warning Signs
|
11
11
|
|
@@ -16,9 +16,11 @@ To install Warning Signs add
|
|
16
16
|
to your gemfile, you will most likely want it to be in all environments, but
|
17
17
|
under some use cases, you may not need it in production.
|
18
18
|
|
19
|
+
### Rails 7.1 is not supported yet, it changed intenral deprecation objects
|
20
|
+
|
19
21
|
## Using Warning Signs
|
20
22
|
|
21
|
-
The Warning Signs
|
23
|
+
The Warning Signs gem looks for a `.warning_signs.yml` file when the Rails
|
22
24
|
application starts. If it does not find the file, it will not load and the
|
23
25
|
processing of deprecations will be unaffected.
|
24
26
|
|
@@ -26,6 +28,8 @@ You should remove any environment settings in Rails that are managing
|
|
26
28
|
`config.active_support.deprecation`, or at least those that are not
|
27
29
|
set to `:notify` -- use WarningSigns to handle those settings...
|
28
30
|
|
31
|
+
### Handlers
|
32
|
+
|
29
33
|
Warning Signs allows you to define _handlers_ in the YAML file. A handler
|
30
34
|
consists of the following:
|
31
35
|
|
@@ -50,7 +54,7 @@ Handlers are matched in order. If no handler applies to a deprecation
|
|
50
54
|
warning, Ruby warnings is ignored, Rails warnings are passed through
|
51
55
|
the ActiveSupport notification mechanism.
|
52
56
|
|
53
|
-
The following
|
57
|
+
The following example logs all deprecation warnings:
|
54
58
|
|
55
59
|
```yaml
|
56
60
|
handlers:
|
@@ -58,6 +62,8 @@ handlers:
|
|
58
62
|
behavior: log
|
59
63
|
```
|
60
64
|
|
65
|
+
### Environments
|
66
|
+
|
61
67
|
Multiple environments need to be handled in a nested list. This example
|
62
68
|
raises exceptions in the test environment, but logs in other environments
|
63
69
|
|
@@ -70,6 +76,8 @@ handlers:
|
|
70
76
|
behavior: log
|
71
77
|
```
|
72
78
|
|
79
|
+
### Sources
|
80
|
+
|
73
81
|
This example raises exceptions for Ruby deprecations, but ignores Rails
|
74
82
|
deprecations:
|
75
83
|
|
@@ -98,6 +106,96 @@ No matter what order you have the behaviors in, a `raise` behavior will be
|
|
98
106
|
executed last so that the other behaviors happen before the exception is
|
99
107
|
invoked.
|
100
108
|
|
109
|
+
### Message Formatters
|
110
|
+
|
111
|
+
Message formatters can affect how and what data is passed to the output
|
112
|
+
channel. You can define one handler:
|
113
|
+
|
114
|
+
```yaml
|
115
|
+
handlers:
|
116
|
+
- environment: all
|
117
|
+
behavior: log
|
118
|
+
message_formatter:
|
119
|
+
backtrace_lines: 3
|
120
|
+
format: hash
|
121
|
+
filter_backtrace: filter_internals
|
122
|
+
```
|
123
|
+
|
124
|
+
There are a few attributes of message formatter that you can set
|
125
|
+
|
126
|
+
* `backtrace_lines` is the number of filtered lines of backtrace, after the
|
127
|
+
current line, that are sent to the output. The default is zero. (For
|
128
|
+
raising exceptions, the default is the entire backtrace).
|
129
|
+
* `format` can be `text`, `json`, `hash`, or `yaml`. Non text formats are
|
130
|
+
hashes with keys `message` and `backtrace`, with the `json` and `yaml`
|
131
|
+
formats converted to strings in those formats.
|
132
|
+
* `filter_backtrace` has three settings. The default is `yes`, which filters
|
133
|
+
out Ruby internals, references to warning signs itself, and lines from
|
134
|
+
gems. To not filter at all, say `no`. To filter internals but not gems,
|
135
|
+
say `filter_internals`.
|
136
|
+
|
137
|
+
If a message formatter is not specified, the default is a hash with zero
|
138
|
+
backtrace lines.
|
139
|
+
|
140
|
+
Or you can define multiple message formatters. These can separate format
|
141
|
+
based on output behavior.
|
142
|
+
|
143
|
+
In this example, `log` behaviors are sent in hash format, while `stderr`
|
144
|
+
behaviors are sent in `text` format. Instead of an `only` list, an `except`
|
145
|
+
list can be specified.
|
146
|
+
|
147
|
+
```yaml
|
148
|
+
handlers:
|
149
|
+
- environment: all
|
150
|
+
behaviors:
|
151
|
+
- log
|
152
|
+
- stderr
|
153
|
+
- raise
|
154
|
+
message_formatters:
|
155
|
+
- backtrace_lines: 3
|
156
|
+
format: hash
|
157
|
+
behaviors:
|
158
|
+
only:
|
159
|
+
- log
|
160
|
+
- backtrace_lines: 3
|
161
|
+
format: text
|
162
|
+
behaviors:
|
163
|
+
only:
|
164
|
+
- stderr
|
165
|
+
```
|
166
|
+
|
167
|
+
You can also define multiple message formatters based on environment.
|
168
|
+
|
169
|
+
In this case, logs in production get hash format, while logs in development
|
170
|
+
get yaml format.
|
171
|
+
|
172
|
+
```yaml
|
173
|
+
handlers:
|
174
|
+
- environment: all
|
175
|
+
behaviors:
|
176
|
+
- log
|
177
|
+
message_formatters:
|
178
|
+
- backtrace_lines: 3
|
179
|
+
format: hash
|
180
|
+
environments:
|
181
|
+
only:
|
182
|
+
- production
|
183
|
+
- backtrace_lines: 3
|
184
|
+
format: yaml
|
185
|
+
environments:
|
186
|
+
only:
|
187
|
+
- development
|
188
|
+
```
|
189
|
+
|
190
|
+
Environments can also be listed negatively with `except`.
|
191
|
+
|
192
|
+
Environment and behavior matching can be used together.
|
193
|
+
|
194
|
+
If no message formatter matches a given message, the default is text format
|
195
|
+
with no backtrace lines.
|
196
|
+
|
197
|
+
### Pattern Matching
|
198
|
+
|
101
199
|
A common pattern is to focus only on specific deprecations and ignore others.
|
102
200
|
For example, this setting file would raise on Ruby keyword argument
|
103
201
|
deprecations and ignore other ruby deprecations
|
@@ -151,11 +249,13 @@ handlers:
|
|
151
249
|
behavior: log
|
152
250
|
```
|
153
251
|
|
252
|
+
### Ruby Warning Types
|
253
|
+
|
154
254
|
Ruby warnings can have an optional category, there are two predefined
|
155
255
|
categories, `deprecated` and `experimental`. You can specify a handler to
|
156
256
|
match those categories based on an "only" or "except" matcher. If you want
|
157
257
|
to specially handle warnings that do not have a defined category, you can
|
158
|
-
refer to them as `blank
|
258
|
+
refer to them as `blank`.
|
159
259
|
|
160
260
|
This handler only handles Ruby warnings that are deprecated, other warnings
|
161
261
|
are ignored.
|
@@ -179,8 +279,3 @@ handlers:
|
|
179
279
|
- blank
|
180
280
|
behavior: log
|
181
281
|
```
|
182
|
-
|
183
|
-
## To Do:
|
184
|
-
|
185
|
-
* write to standard out as a behavior
|
186
|
-
* Ability to customize output message format
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
module Behavior
|
3
|
+
class Base
|
4
|
+
attr_reader :message_formatter, :message, :backtrace
|
5
|
+
|
6
|
+
def self.for(behavior_type, *args)
|
7
|
+
class_name = "WarningSigns::Behavior::#{behavior_type.classify}"
|
8
|
+
class_name.constantize.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(message, backtrace, message_formatter)
|
12
|
+
@message = message
|
13
|
+
@backtrace = backtrace
|
14
|
+
@message_formatter = message_formatter
|
15
|
+
end
|
16
|
+
|
17
|
+
def formatted_message
|
18
|
+
result = message_formatter.format_message(message, backtrace)
|
19
|
+
result = [result] unless result.is_a?(Array)
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
module Behavior
|
3
|
+
class Raise < Base
|
4
|
+
def filtered_backtrace
|
5
|
+
return backtrace if message_formatter.backtrace_lines.zero?
|
6
|
+
message_formatter.filtered_backtrace(backtrace)
|
7
|
+
end
|
8
|
+
|
9
|
+
def emit
|
10
|
+
raise UnhandledDeprecationError,
|
11
|
+
formatted_message.first,
|
12
|
+
filtered_backtrace[1..].map(&:to_s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
module CallerHelper
|
3
|
+
def caller_filtered
|
4
|
+
caller.reject do |location|
|
5
|
+
ignore_line(location.to_s)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def ignore_line(line, filter_backtraces: "yes".inquiry)
|
10
|
+
return false if filter_backtraces.no?
|
11
|
+
partial_result = line.include?("<internal:") ||
|
12
|
+
line.include?("warning_signs/lib") ||
|
13
|
+
line.include?("warning_signs/spec")
|
14
|
+
return partial_result if filter_backtraces.filter_internals?
|
15
|
+
partial_result ||
|
16
|
+
line.include?("rubygems") ||
|
17
|
+
line.include?("/gems")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,17 +1,22 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Deprecation
|
3
|
-
attr_accessor :message, :source, :category
|
3
|
+
attr_accessor :message, :source, :category, :backtrace
|
4
4
|
|
5
|
-
def initialize(message, source:, category: nil)
|
5
|
+
def initialize(message, source:, category: nil, backtrace: [])
|
6
6
|
@message = message
|
7
7
|
@source = source.to_s.downcase.inquiry
|
8
8
|
@category = category
|
9
|
+
@backtrace = backtrace || []
|
9
10
|
end
|
10
11
|
|
11
12
|
def handler
|
12
13
|
World.instance.handler_for(self)
|
13
14
|
end
|
14
15
|
|
16
|
+
def message_formatter_for(behavior)
|
17
|
+
handler.message_formatter_for(behavior)
|
18
|
+
end
|
19
|
+
|
15
20
|
# force raise to be the last element if it is present
|
16
21
|
def behaviors
|
17
22
|
result = (handler&.environment&.behaviors || []).inquiry
|
@@ -20,15 +25,13 @@ module WarningSigns
|
|
20
25
|
end
|
21
26
|
|
22
27
|
def invoke
|
23
|
-
behaviors.each do |
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
$stderr.puts(message) # standard:disable Style/StderrPuts
|
31
|
-
end
|
28
|
+
behaviors.each do |behavior_type|
|
29
|
+
Behavior::Base.for(
|
30
|
+
behavior_type,
|
31
|
+
message,
|
32
|
+
backtrace,
|
33
|
+
message_formatter_for(behavior_type)
|
34
|
+
).emit
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Handler
|
3
|
-
attr_accessor :environments, :
|
3
|
+
attr_accessor :environments, :only_except, :source,
|
4
|
+
:category_matcher, :backtrace_lines, :message_formatters
|
4
5
|
|
5
6
|
def self.from_hash(hash)
|
6
7
|
new(**hash.symbolize_keys)
|
@@ -14,27 +15,48 @@ module WarningSigns
|
|
14
15
|
only: [],
|
15
16
|
source: "any",
|
16
17
|
environments: [],
|
17
|
-
ruby_warnings: {}
|
18
|
+
ruby_warnings: {},
|
19
|
+
message_formatter: nil,
|
20
|
+
message_formatters: []
|
18
21
|
)
|
19
|
-
@
|
20
|
-
|
22
|
+
@only_except = OnlyExcept.new(
|
23
|
+
only: only.map { Pattern.for(_1) },
|
24
|
+
except: except.map { Pattern.for(_1) }
|
25
|
+
)
|
21
26
|
@environments = environments.map { Environment.new(**_1.symbolize_keys) }
|
22
27
|
if environment.present?
|
23
|
-
@environments << Environment.new(
|
28
|
+
@environments << Environment.new(
|
29
|
+
environment: environment,
|
30
|
+
behaviors: behaviors,
|
31
|
+
behavior: behavior
|
32
|
+
)
|
24
33
|
end
|
25
34
|
@source = source.to_s.downcase.inquiry
|
26
35
|
@category_matcher = RubyCategoryMatcher.new(**ruby_warnings.symbolize_keys)
|
36
|
+
@message_formatters = MessageFormatterList.new(
|
37
|
+
message_formatters: message_formatters,
|
38
|
+
message_formatter: message_formatter
|
39
|
+
)
|
27
40
|
raise InvalidHandlerError unless valid?
|
28
41
|
end
|
29
42
|
|
43
|
+
def message_formatter_for(behavior)
|
44
|
+
message_formatters.behavior_match(behavior) ||
|
45
|
+
MessageFormatter::Text.new
|
46
|
+
end
|
47
|
+
|
30
48
|
def valid?
|
31
|
-
|
49
|
+
only_except.valid?
|
32
50
|
end
|
33
51
|
|
34
52
|
def known_source?(deprecation_source)
|
35
53
|
deprecation_source.in?(%w[ruby rails])
|
36
54
|
end
|
37
55
|
|
56
|
+
def pattern_match?(message)
|
57
|
+
only_except.only_except_match?(message)
|
58
|
+
end
|
59
|
+
|
38
60
|
def match?(deprecation)
|
39
61
|
source_match?(deprecation.source) &&
|
40
62
|
pattern_match?(deprecation.message) &&
|
@@ -45,29 +67,11 @@ module WarningSigns
|
|
45
67
|
category_matcher.match?(category)
|
46
68
|
end
|
47
69
|
|
48
|
-
def pattern_match?(message)
|
49
|
-
only_match?(message) && except_match?(message)
|
50
|
-
end
|
51
|
-
|
52
70
|
def source_match?(deprecation_source)
|
53
71
|
return known_source?(deprecation_source) if source.any?
|
54
72
|
source == deprecation_source
|
55
73
|
end
|
56
74
|
|
57
|
-
def only_match?(message)
|
58
|
-
return true if only.empty?
|
59
|
-
only.any? do |only_pattern|
|
60
|
-
only_pattern.match?(message)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def except_match?(message)
|
65
|
-
return true if except.empty?
|
66
|
-
except.none? do |except_pattern|
|
67
|
-
except_pattern.match?(message)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
75
|
def enabled_for_ruby?
|
72
76
|
source.ruby? || source.all?
|
73
77
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
module MessageFormatter
|
3
|
+
class Base
|
4
|
+
include CallerHelper
|
5
|
+
attr_reader :backtrace_lines, :behaviors, :environments, :filter_backtraces
|
6
|
+
|
7
|
+
def self.for(**args)
|
8
|
+
args = args.symbolize_keys
|
9
|
+
type = args.delete(:format) || "text"
|
10
|
+
class_name = "WarningSigns::MessageFormatter::#{type.classify}"
|
11
|
+
class_name.constantize.new(**args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(backtrace_lines: 0, behaviors: {}, environments: {}, filter_backtraces: "yes")
|
15
|
+
@backtrace_lines = backtrace_lines
|
16
|
+
@behaviors = OnlyExcept.new(**behaviors.symbolize_keys)
|
17
|
+
@environments = OnlyExcept.new(**environments.symbolize_keys)
|
18
|
+
@filter_backtraces = filter_backtraces.to_s.downcase.inquiry
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_message(message, backtrace)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def filtered_backtrace(backtrace)
|
26
|
+
return [] if backtrace.nil?
|
27
|
+
result = backtrace.reject do |location|
|
28
|
+
ignore_line(location.to_s, filter_backtraces: filter_backtraces)
|
29
|
+
end
|
30
|
+
result.empty? ? backtrace : result
|
31
|
+
end
|
32
|
+
|
33
|
+
def filtered_backtrace_lines(backtrace)
|
34
|
+
return [] if backtrace_lines.zero?
|
35
|
+
filtered_backtrace(backtrace)[1..backtrace_lines] || []
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
class MessageFormatterList
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :message_formatters
|
6
|
+
|
7
|
+
def initialize(message_formatters: [], message_formatter: nil)
|
8
|
+
@message_formatters = message_formatters.map do
|
9
|
+
MessageFormatter::Base.for(**_1)
|
10
|
+
end
|
11
|
+
@message_formatters << MessageFormatter::Base.for(**message_formatter) if message_formatter
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
message_formatters.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def behavior_match(behavior)
|
19
|
+
message_formatters.find do
|
20
|
+
_1.behaviors.only_except_match?(behavior) &&
|
21
|
+
_1.environments.only_except_match?(Rails.env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
class OnlyExcept
|
3
|
+
attr_accessor :only, :except
|
4
|
+
|
5
|
+
def initialize(only: [], except: [])
|
6
|
+
@only = only
|
7
|
+
@except = except
|
8
|
+
end
|
9
|
+
|
10
|
+
def only_except_match?(message)
|
11
|
+
only_match?(message) && except_match?(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def only_match?(message)
|
15
|
+
return true if only.empty?
|
16
|
+
only.any? do |only_pattern|
|
17
|
+
only_pattern.match?(message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def except_match?(message)
|
22
|
+
return true if except.empty?
|
23
|
+
except.none? do |except_pattern|
|
24
|
+
except_pattern.match?(message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
except.empty? || only.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,25 +1,19 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
module RubyDeprecationCatcher
|
3
|
+
include CallerHelper
|
4
|
+
|
3
5
|
def warn(message, category: nil)
|
4
6
|
Deprecation.new(
|
5
7
|
augmented_message(message, category),
|
6
8
|
source: "ruby",
|
7
|
-
category: category
|
9
|
+
category: category,
|
10
|
+
backtrace: caller
|
8
11
|
).invoke
|
9
12
|
end
|
10
13
|
|
11
14
|
def augmented_message(message, category)
|
12
15
|
category_part = category.present? ? " #{category.upcase}: " : ": "
|
13
|
-
"RUBY WARNING#{category_part}#{message} called from #{
|
14
|
-
end
|
15
|
-
|
16
|
-
def caller_location
|
17
|
-
caller_locations.find do |location|
|
18
|
-
!location.to_s.include?("internal:warning") &&
|
19
|
-
!location.to_s.include?("warning_signs") &&
|
20
|
-
!location.to_s.include?("rubygems") &&
|
21
|
-
!location.to_s.include?("/gems")
|
22
|
-
end
|
16
|
+
"RUBY WARNING#{category_part}#{message} called from #{caller_filtered.first}"
|
23
17
|
end
|
24
18
|
end
|
25
19
|
end
|
data/lib/warning_signs.rb
CHANGED
data/warning_signs.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warning_signs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noel Rappin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: railties
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - "<="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 7.1.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "<="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 7.1.0
|
153
153
|
description: A gem for managing ruby and rails deprecation warnings
|
154
154
|
email:
|
155
155
|
- noelrap@hey.com
|
@@ -170,9 +170,23 @@ files:
|
|
170
170
|
- bin/console
|
171
171
|
- bin/setup
|
172
172
|
- lib/warning_signs.rb
|
173
|
+
- lib/warning_signs/behavior/base.rb
|
174
|
+
- lib/warning_signs/behavior/ignore.rb
|
175
|
+
- lib/warning_signs/behavior/log.rb
|
176
|
+
- lib/warning_signs/behavior/raise.rb
|
177
|
+
- lib/warning_signs/behavior/stderr.rb
|
178
|
+
- lib/warning_signs/behavior/stdout.rb
|
179
|
+
- lib/warning_signs/caller_helper.rb
|
173
180
|
- lib/warning_signs/deprecation.rb
|
174
181
|
- lib/warning_signs/environment.rb
|
175
182
|
- lib/warning_signs/handler.rb
|
183
|
+
- lib/warning_signs/message_formatter/base.rb
|
184
|
+
- lib/warning_signs/message_formatter/hash.rb
|
185
|
+
- lib/warning_signs/message_formatter/json.rb
|
186
|
+
- lib/warning_signs/message_formatter/text.rb
|
187
|
+
- lib/warning_signs/message_formatter/yaml.rb
|
188
|
+
- lib/warning_signs/message_formatter_list.rb
|
189
|
+
- lib/warning_signs/only_except.rb
|
176
190
|
- lib/warning_signs/pattern.rb
|
177
191
|
- lib/warning_signs/rails_deprecation_catcher.rb
|
178
192
|
- lib/warning_signs/railtie.rb
|