structured_warnings 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 82e448e3265ea35dd71196fb6f3adbc6b629cbb5
4
- data.tar.gz: 5ed838c91e79e3d459f10d2cb9c7b596f03b5d98
2
+ SHA256:
3
+ metadata.gz: 9d6ae32c5d463eb0efeba1057728863feb4d4dcbce402934626f3423efb545b6
4
+ data.tar.gz: a9f5fd53fa29a245d0190a27d4743225ea02af03fdcd04865d14625a3c9bfdc4
5
5
  SHA512:
6
- metadata.gz: c784e0acb8c6aa8840ba44a36f5fdd090d7a46d178b4701fc97f1c6203d0f0de41f8d90a8579a53a7064a4df9146a314a936b6c6d290c892d3022840bce58282
7
- data.tar.gz: f816ed5e9f249359c9c8108ba65c978140f9c2cef49f7d70202b26537ba4ced18ad1699c76ee9954ea8771bde64da59e98a08f34deee41766b06f76328a836df
6
+ metadata.gz: 3e0245fce924551f6881319642edba0685abe1a16b4e572b8532789c4188b9a529a9fd629125c10e27e0dbccc7bee1caef394fd690775e62de0769763d112d98
7
+ data.tar.gz: 6625b90aca3e9c0245608bdb3b81c4fb882c9f564a40abc29aaa598909e93a08ac2a99bdd4921284561c9253125f0d68e3191d92a3fb81068b36d30c246570d6
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # StructuredWarnings
2
2
 
3
- > **Disclaimer:** This is an experimental reimplementation of structured
4
- > warnings, based on Ruby 2.4's new warning module. This is not yet ready for
5
- > prime time.
6
-
7
3
  This is an implementation of Daniel Berger's [proposal of structured warnings
8
4
  for Ruby](https://web.archive.org/web/20140328021259/http://www.oreillynet.com/ruby/blog/2008/02/structured_warnings_now.html).
9
5
  They provide dynamic suppression and activation, as well as, an inheritance
@@ -5,7 +5,7 @@ class StructuredWarnings::Test::Warner < StructuredWarnings::Warner
5
5
  # Overrides the public interface of StructuredWarnings::Warner. This
6
6
  # method always returns nil to avoid warnings on stdout during assert_warn
7
7
  # and assert_no_warn blocks.
8
- def format(warning, message, call_stack)
8
+ def format(warning, message, options, call_stack)
9
9
  given_warnings << warning.new(message)
10
10
  nil
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module StructuredWarnings
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -5,11 +5,15 @@
5
5
  class StructuredWarnings::Warner
6
6
  # Warner.new.format(StructuredWarning::DeprecationWarning, "more info..", caller)
7
7
  # # => "demo.rb:5 : more info.. (StructuredWarning::DeprecationWarning)"
8
- def format(warning, message, stack)
8
+ def format(warning, message, options, stack)
9
9
  frame = stack.shift
10
10
  # This file contains the backwards compatibility code for Ruby 2.3 and
11
11
  # lower, let's skip it
12
12
  frame = stack.shift if frame.include? 'lib/structured_warnings/kernel.rb'
13
- "#{frame} : #{message} (#{warning})"
13
+
14
+ # Handle introduced uplevel introduced in Ruby 2.5
15
+ frame = stack.shift(options[:uplevel]).last if options[:uplevel]
16
+
17
+ "#{frame}: #{message} (#{warning})\n"
14
18
  end
15
19
  end
@@ -46,23 +46,24 @@ module StructuredWarnings::Warning
46
46
  warning = first.class
47
47
  message = first.message
48
48
 
49
- else
50
- warning =
51
- if caller.shift.include? 'lib/structured_warnings/kernel.rb'
52
- StructuredWarnings::StandardWarning
53
- else
54
- StructuredWarnings::BuiltInWarning
55
- end
49
+ elsif caller.shift.include? 'lib/structured_warnings/kernel.rb'
50
+ warning = StructuredWarnings::StandardWarning
56
51
  message = first.to_s
52
+
53
+ else
54
+ warning = StructuredWarnings::BuiltInWarning
55
+ message = first.to_s.split(':', 4).last[1..-2]
57
56
  end
58
57
 
58
+ options = args.first.is_a?(Hash) ? args.shift : {}
59
+
59
60
  # If args is not empty, user passed an incompatible set of arguments.
60
61
  # Maybe somebody else is overriding warn as well and knows, what to do.
61
62
  # Better do nothing in this case. See #5
62
63
  return super unless args.empty?
63
64
 
64
65
  if warning.active?
65
- output = StructuredWarnings.warner.format(warning, message, caller(1))
66
+ output = StructuredWarnings.warner.format(warning, message, options, caller(1))
66
67
  super(output) unless output.nil? or output.to_s.empty?
67
68
  end
68
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structured_warnings
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
  - Gregor Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.6.10
110
+ rubygems_version: 3.0.6
112
111
  signing_key:
113
112
  specification_version: 4
114
113
  summary: Provides structured warnings for Ruby, using an exception-like interface