warning_signs 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5dd43f86a3822293460f2d79efb2c2e98a5cb6a86ca5b85a3d762b4e9b82a8e
4
- data.tar.gz: 9dd3da0dbd012564356f1c477038f9cd5b00652149c064aea4006224b408940f
3
+ metadata.gz: ffe169d3fa9e10de71c8ca43c6ac4cf8dd3c036f716d9a9f608fc37ce01a1879
4
+ data.tar.gz: a7511cdd8e836b8e1906b8c44a9ea3ec3309918fd033935a05480f7179bc4722
5
5
  SHA512:
6
- metadata.gz: 4e73a2bc35a1283b56061fad2717c6b0c9ce19f91c34b81645bf57c9e4c09eee2f93f727529c107a54c2e47fa6a8d88b9958af522b3a12929d18f505924b734f
7
- data.tar.gz: eb2050074df9f17103a57ebbf506cba97a9f0a4b17d82db8b968c359751edbb8787033c708d19b5bb2e2b57b49346f138576f9cd98552cca80f12578d4ce908a
6
+ metadata.gz: babffad1137746742209cf4fe4adc14f7b2a905684b31f8e68569ccdcc9806945b88e690b75262bf62b9c4d09be77eb87cc5c7aeac58bc947d3ff3165eda9854
7
+ data.tar.gz: 23750e8b4849c3a1bd2d349fb26696e36eb34afcd71e0e3cb04619ed32234549f880cdc5f28e2d1da5fc57b1b1b519fc705ea75fe00de582c82e8612129473e8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.0
2
+
3
+ * Allow handlers to take into account Ruby warning categories
4
+ * Ruby warning message better handles Ruby warning categories
5
+
1
6
  ## 0.3.0
2
7
 
3
8
  * Allow multiple behaviors in a single environment
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- warning_signs (0.3.0)
4
+ warning_signs (0.4.0)
5
5
  awesome_print
6
6
  railties
7
7
 
data/README.md CHANGED
@@ -150,3 +150,37 @@ handlers:
150
150
  - environment: other
151
151
  behavior: log
152
152
  ```
153
+
154
+ Ruby warnings can have an optional category, there are two predefined
155
+ categories, `deprecated` and `experimental`. You can specify a handler to
156
+ match those categories based on an "only" or "except" matcher. If you want
157
+ to specially handle warnings that do not have a defined category, you can
158
+ refer to them as `blank`,
159
+
160
+ This handler only handles Ruby warnings that are deprecated, other warnings
161
+ are ignored.
162
+
163
+ ```yaml
164
+ handlers:
165
+ - environment: all
166
+ ruby_warnings:
167
+ only:
168
+ - deprecated
169
+ behavior: log
170
+ ```
171
+
172
+ This handler handles any Ruby warning with a category
173
+
174
+ ```yaml
175
+ handlers:
176
+ - environment: all
177
+ ruby_warnings:
178
+ except:
179
+ - blank
180
+ behavior: log
181
+ ```
182
+
183
+ ## To Do:
184
+
185
+ * write to standard out as a behavior
186
+ * Ability to customize output message format
@@ -1,10 +1,11 @@
1
1
  module WarningSigns
2
2
  class Deprecation
3
- attr_accessor :message, :source
3
+ attr_accessor :message, :source, :category
4
4
 
5
- def initialize(message, source:)
5
+ def initialize(message, source:, category: nil)
6
6
  @message = message
7
7
  @source = source.to_s.downcase.inquiry
8
+ @category = category
8
9
  end
9
10
 
10
11
  def handler
@@ -14,7 +15,7 @@ module WarningSigns
14
15
  # force raise to be the last element if it is present
15
16
  def behaviors
16
17
  result = (handler&.environment&.behaviors || []).inquiry
17
- return result if !result.raise?
18
+ return result unless result.raise?
18
19
  (result - ["raise"]) << "raise"
19
20
  end
20
21
 
@@ -1,6 +1,6 @@
1
1
  module WarningSigns
2
2
  class Handler
3
- attr_accessor :environments, :except, :only, :source
3
+ attr_accessor :environments, :except, :only, :source, :category_matcher
4
4
 
5
5
  def self.from_hash(hash)
6
6
  new(**hash.symbolize_keys)
@@ -13,7 +13,8 @@ module WarningSigns
13
13
  except: [],
14
14
  only: [],
15
15
  source: "any",
16
- environments: []
16
+ environments: [],
17
+ ruby_warnings: {}
17
18
  )
18
19
  @except = except.map { Pattern.for(_1) }
19
20
  @only = only.map { Pattern.for(_1) }
@@ -22,6 +23,7 @@ module WarningSigns
22
23
  @environments << Environment.new(environment: environment, behaviors: behaviors, behavior: behavior)
23
24
  end
24
25
  @source = source.to_s.downcase.inquiry
26
+ @category_matcher = RubyCategoryMatcher.new(**ruby_warnings.symbolize_keys)
25
27
  raise InvalidHandlerError unless valid?
26
28
  end
27
29
 
@@ -35,7 +37,12 @@ module WarningSigns
35
37
 
36
38
  def match?(deprecation)
37
39
  source_match?(deprecation.source) &&
38
- pattern_match?(deprecation.message)
40
+ pattern_match?(deprecation.message) &&
41
+ category_match?(deprecation.category)
42
+ end
43
+
44
+ def category_match?(category)
45
+ category_matcher.match?(category)
39
46
  end
40
47
 
41
48
  def pattern_match?(message)
@@ -0,0 +1,29 @@
1
+ module WarningSigns
2
+ class RubyCategoryMatcher
3
+ attr_accessor :only, :except
4
+
5
+ def initialize(only: [], except: [])
6
+ @only = only.compact.map { _1.to_sym }
7
+ @except = except.compact.map { _1.to_sym }
8
+ end
9
+
10
+ def match?(category)
11
+ category = :blank if category.blank?
12
+ only_match?(category) && except_match?(category)
13
+ end
14
+
15
+ def only_match?(category)
16
+ return true if only.empty?
17
+ only.any? do |only_pattern|
18
+ only_pattern === category&.to_sym
19
+ end
20
+ end
21
+
22
+ def except_match?(category)
23
+ return true if except.empty?
24
+ except.none? do |except_pattern|
25
+ except_pattern === category&.to_sym
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,11 +1,16 @@
1
1
  module WarningSigns
2
2
  module RubyDeprecationCatcher
3
- def warn(message)
4
- Deprecation.new(augmented_message(message), source: "ruby").invoke
3
+ def warn(message, category: nil)
4
+ Deprecation.new(
5
+ augmented_message(message, category),
6
+ source: "ruby",
7
+ category: category
8
+ ).invoke
5
9
  end
6
10
 
7
- def augmented_message(message)
8
- "RUBY DEPRECATION WARNING: #{message} called from #{caller_location}"
11
+ def augmented_message(message, category)
12
+ category_part = category.present? ? " #{category.upcase}: " : ": "
13
+ "RUBY WARNING#{category_part}#{message} called from #{caller_location}"
9
14
  end
10
15
 
11
16
  def caller_location
@@ -1,3 +1,3 @@
1
1
  module WarningSigns
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.0
4
+ version: 0.4.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-05-05 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -177,6 +177,7 @@ files:
177
177
  - lib/warning_signs/rails_deprecation_catcher.rb
178
178
  - lib/warning_signs/railtie.rb
179
179
  - lib/warning_signs/regex_pattern.rb
180
+ - lib/warning_signs/ruby_category_matcher.rb
180
181
  - lib/warning_signs/ruby_deprecation_catcher.rb
181
182
  - lib/warning_signs/string_pattern.rb
182
183
  - lib/warning_signs/version.rb