warning_signs 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +8 -8
- data/README.md +92 -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 +13 -22
- data/lib/warning_signs/handler.rb +27 -26
- 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 +1 -2
- data/lib/warning_signs/ruby_deprecation_catcher.rb +4 -3
- data/lib/warning_signs/version.rb +1 -1
- data/lib/warning_signs.rb +1 -0
- data/warning_signs.gemspec +1 -1
- metadata +20 -7
- data/lib/warning_signs/caller_location_helper.rb +0 -17
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,13 @@
|
|
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
|
+
|
1
11
|
## 0.5.0
|
2
12
|
|
3
13
|
* Allow handlers to print out backtraces for log, stdout, and stderr behaviors
|
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
@@ -16,6 +16,8 @@ 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
23
|
The Warning Signs gem looks for a `.warning_signs.yml` file when the Rails
|
@@ -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
|
|
@@ -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,20 +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
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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:
|
105
113
|
|
106
114
|
```yaml
|
107
115
|
handlers:
|
108
116
|
- environment: all
|
109
|
-
|
110
|
-
|
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
|
111
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:
|
112
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
|
113
188
|
```
|
114
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
|
+
|
115
199
|
A common pattern is to focus only on specific deprecations and ignore others.
|
116
200
|
For example, this setting file would raise on Ruby keyword argument
|
117
201
|
deprecations and ignore other ruby deprecations
|
@@ -165,6 +249,8 @@ handlers:
|
|
165
249
|
behavior: log
|
166
250
|
```
|
167
251
|
|
252
|
+
### Ruby Warning Types
|
253
|
+
|
168
254
|
Ruby warnings can have an optional category, there are two predefined
|
169
255
|
categories, `deprecated` and `experimental`. You can specify a handler to
|
170
256
|
match those categories based on an "only" or "except" matcher. If you want
|
@@ -193,7 +279,3 @@ handlers:
|
|
193
279
|
- blank
|
194
280
|
behavior: log
|
195
281
|
```
|
196
|
-
|
197
|
-
## To Do:
|
198
|
-
|
199
|
-
* 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
|
@@ -2,17 +2,21 @@ module WarningSigns
|
|
2
2
|
class Deprecation
|
3
3
|
attr_accessor :message, :source, :category, :backtrace
|
4
4
|
|
5
|
-
def initialize(message, source:, category: nil, backtrace:
|
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
|
+
@backtrace = backtrace || []
|
10
10
|
end
|
11
11
|
|
12
12
|
def handler
|
13
13
|
World.instance.handler_for(self)
|
14
14
|
end
|
15
15
|
|
16
|
+
def message_formatter_for(behavior)
|
17
|
+
handler.message_formatter_for(behavior)
|
18
|
+
end
|
19
|
+
|
16
20
|
# force raise to be the last element if it is present
|
17
21
|
def behaviors
|
18
22
|
result = (handler&.environment&.behaviors || []).inquiry
|
@@ -20,27 +24,14 @@ module WarningSigns
|
|
20
24
|
(result - ["raise"]) << "raise"
|
21
25
|
end
|
22
26
|
|
23
|
-
def backtrace_lines
|
24
|
-
lines = handler&.backtrace_lines || 0
|
25
|
-
return "" if lines.zero?
|
26
|
-
backtrace[1..lines].join("\n")
|
27
|
-
end
|
28
|
-
|
29
27
|
def invoke
|
30
|
-
behaviors.each do |
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
when "stderr"
|
38
|
-
$stderr.puts(message) # standard:disable Style/StderrPuts
|
39
|
-
$stderr.puts(backtrace_lines) # standard:disable Style/StderrPuts
|
40
|
-
when "stdout"
|
41
|
-
$stdout.puts(message) # standard:disable Style/StdoutPuts
|
42
|
-
$stdout.puts(backtrace_lines) # standard:disable Style/StdoutPuts
|
43
|
-
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
|
44
35
|
end
|
45
36
|
end
|
46
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Handler
|
3
|
-
attr_accessor :environments, :
|
4
|
-
:category_matcher, :backtrace_lines
|
3
|
+
attr_accessor :environments, :only_except, :source,
|
4
|
+
:category_matcher, :backtrace_lines, :message_formatters
|
5
5
|
|
6
6
|
def self.from_hash(hash)
|
7
7
|
new(**hash.symbolize_keys)
|
@@ -16,28 +16,47 @@ module WarningSigns
|
|
16
16
|
source: "any",
|
17
17
|
environments: [],
|
18
18
|
ruby_warnings: {},
|
19
|
-
|
19
|
+
message_formatter: nil,
|
20
|
+
message_formatters: []
|
20
21
|
)
|
21
|
-
@
|
22
|
-
|
22
|
+
@only_except = OnlyExcept.new(
|
23
|
+
only: only.map { Pattern.for(_1) },
|
24
|
+
except: except.map { Pattern.for(_1) }
|
25
|
+
)
|
23
26
|
@environments = environments.map { Environment.new(**_1.symbolize_keys) }
|
24
27
|
if environment.present?
|
25
|
-
@environments << Environment.new(
|
28
|
+
@environments << Environment.new(
|
29
|
+
environment: environment,
|
30
|
+
behaviors: behaviors,
|
31
|
+
behavior: behavior
|
32
|
+
)
|
26
33
|
end
|
27
34
|
@source = source.to_s.downcase.inquiry
|
28
35
|
@category_matcher = RubyCategoryMatcher.new(**ruby_warnings.symbolize_keys)
|
29
|
-
@
|
36
|
+
@message_formatters = MessageFormatterList.new(
|
37
|
+
message_formatters: message_formatters,
|
38
|
+
message_formatter: message_formatter
|
39
|
+
)
|
30
40
|
raise InvalidHandlerError unless valid?
|
31
41
|
end
|
32
42
|
|
43
|
+
def message_formatter_for(behavior)
|
44
|
+
message_formatters.behavior_match(behavior) ||
|
45
|
+
MessageFormatter::Text.new
|
46
|
+
end
|
47
|
+
|
33
48
|
def valid?
|
34
|
-
|
49
|
+
only_except.valid?
|
35
50
|
end
|
36
51
|
|
37
52
|
def known_source?(deprecation_source)
|
38
53
|
deprecation_source.in?(%w[ruby rails])
|
39
54
|
end
|
40
55
|
|
56
|
+
def pattern_match?(message)
|
57
|
+
only_except.only_except_match?(message)
|
58
|
+
end
|
59
|
+
|
41
60
|
def match?(deprecation)
|
42
61
|
source_match?(deprecation.source) &&
|
43
62
|
pattern_match?(deprecation.message) &&
|
@@ -48,29 +67,11 @@ module WarningSigns
|
|
48
67
|
category_matcher.match?(category)
|
49
68
|
end
|
50
69
|
|
51
|
-
def pattern_match?(message)
|
52
|
-
only_match?(message) && except_match?(message)
|
53
|
-
end
|
54
|
-
|
55
70
|
def source_match?(deprecation_source)
|
56
71
|
return known_source?(deprecation_source) if source.any?
|
57
72
|
source == deprecation_source
|
58
73
|
end
|
59
74
|
|
60
|
-
def only_match?(message)
|
61
|
-
return true if only.empty?
|
62
|
-
only.any? do |only_pattern|
|
63
|
-
only_pattern.match?(message)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def except_match?(message)
|
68
|
-
return true if except.empty?
|
69
|
-
except.none? do |except_pattern|
|
70
|
-
except_pattern.match?(message)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
75
|
def enabled_for_ruby?
|
75
76
|
source.ruby? || source.all?
|
76
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,13 +1,12 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class RailsDeprecationCatcher < ActiveSupport::Subscriber
|
3
|
-
include CallerLocationHelper
|
4
3
|
attach_to :rails
|
5
4
|
|
6
5
|
def deprecation(event)
|
7
6
|
Deprecation.new(
|
8
7
|
event.payload[:message],
|
9
8
|
source: "rails",
|
10
|
-
backtrace:
|
9
|
+
backtrace: caller
|
11
10
|
).invoke
|
12
11
|
end
|
13
12
|
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
module RubyDeprecationCatcher
|
3
|
-
include
|
3
|
+
include CallerHelper
|
4
|
+
|
4
5
|
def warn(message, category: nil)
|
5
6
|
Deprecation.new(
|
6
7
|
augmented_message(message, category),
|
7
8
|
source: "ruby",
|
8
9
|
category: category,
|
9
|
-
backtrace:
|
10
|
+
backtrace: caller
|
10
11
|
).invoke
|
11
12
|
end
|
12
13
|
|
13
14
|
def augmented_message(message, category)
|
14
15
|
category_part = category.present? ? " #{category.upcase}: " : ": "
|
15
|
-
"RUBY WARNING#{category_part}#{message} called from #{
|
16
|
+
"RUBY WARNING#{category_part}#{message} called from #{caller_filtered.first}"
|
16
17
|
end
|
17
18
|
end
|
18
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,10 +170,23 @@ files:
|
|
170
170
|
- bin/console
|
171
171
|
- bin/setup
|
172
172
|
- lib/warning_signs.rb
|
173
|
-
- lib/warning_signs/
|
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
|
174
180
|
- lib/warning_signs/deprecation.rb
|
175
181
|
- lib/warning_signs/environment.rb
|
176
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
|
177
190
|
- lib/warning_signs/pattern.rb
|
178
191
|
- lib/warning_signs/rails_deprecation_catcher.rb
|
179
192
|
- lib/warning_signs/railtie.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module WarningSigns
|
2
|
-
module CallerLocationHelper
|
3
|
-
def caller_location_start
|
4
|
-
caller_locations.find_index do |location|
|
5
|
-
!ignore_line(location.to_s)
|
6
|
-
end || 0
|
7
|
-
end
|
8
|
-
|
9
|
-
def ignore_line(line)
|
10
|
-
line.include?("<internal:") ||
|
11
|
-
line.include?("warning_signs/lib") ||
|
12
|
-
line.include?("warning_signs/spec") ||
|
13
|
-
line.include?("rubygems") ||
|
14
|
-
line.include?("/gems")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|