multiple_devices_logger 3.0.1 → 3.1.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
2
  SHA1:
3
- metadata.gz: 6ff791771ff967eefdab5f35a76f510f2ae946b4
4
- data.tar.gz: a064e0884d969d4f436c9d0979a54b204e3c8e06
3
+ metadata.gz: 19415b2e0ea7cb895f6b6fd64c56f32f318ee830
4
+ data.tar.gz: 1b9e00b61d944926836be3b48ade2cea0fca0c56
5
5
  SHA512:
6
- metadata.gz: 9c3dc5dc90df7c5779c95e3f84f5ed770ce4bc3a7f1f722cb2d15d180c3f57a2dbe726f926b63371a6ecdb8690103fc74067172d57ed06be0512b4203c3fad96
7
- data.tar.gz: c0a18626679ca71dde88e484544e62004ff61f103ecf2ed2f38a28b4e015a2ed688308e2c5ab0e0112576209bc12a0c25eaee84cfa3b05f77459bbf8993c16f3
6
+ metadata.gz: d7c48a83c54d635bfb61ed4b79e406420225f369d240379af2b23cae1d34c9ab417b80a25292b8e8c71aacd434d111706cc1695f785e4f1d9236631e64e7e221
7
+ data.tar.gz: 4f2982efb97ce01c87b089aee3d59f2da66f4753f88e049f24f4d2096d5ca165cc56934763c0f8262e1cf5d73fc9989437a7b963775f4346d04b3358c2bdc9fc
data/README.mdown CHANGED
@@ -94,6 +94,12 @@ the device:
94
94
  logger.add_device(STDERR, :debug, ignore_exceptions: [IOError, ArgumentError])
95
95
  ```
96
96
 
97
+ In addition to classes, A lambda can be given to ignore exception, example:
98
+
99
+ ```ruby
100
+ logger.ignore_exceptions(ArgumentError, -> (e) { e.message =~ /404/ }
101
+ ```
102
+
97
103
  ## Executing test suite
98
104
 
99
105
  This project is fully tested with [Rspec 3](http://github.com/rspec/rspec).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.1.0
@@ -5,17 +5,22 @@ class MultipleDevicesLogger
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  def exception_ignored?(exception)
8
- exception.is_a?(Exception) && ignored_exception_classes.any? do |klass|
9
- exception.is_a?(klass)
10
- end
8
+ return false unless exception.is_a?(Exception)
9
+ ignored_exception_classes.any? { |klass| exception.is_a?(klass) } || ignored_exceptions_procs.any? { |proc| proc.call(exception) }
11
10
  end
12
11
 
13
- def ignore_exceptions(*classes)
12
+ def ignore_exceptions(*arguments, &block)
14
13
  @ignored_exception_class_names ||= []
15
- [classes].flatten.each do |class_name|
16
- klass = class_name.is_a?(Class) ? class_name : class_name.to_s.presence.try(:constantize)
17
- raise("Invalid exception class: #{class_name.inspect}") unless klass.is_a?(Class) && (klass == Exception || (klass < Exception))
18
- @ignored_exception_class_names << klass.name
14
+ @ignored_exceptions_procs ||= []
15
+ @ignored_exceptions_procs << Proc.new(&block) if block_given?
16
+ [arguments].flatten.each do |argument|
17
+ if argument.respond_to?(:call)
18
+ @ignored_exceptions_procs << argument
19
+ else
20
+ klass = argument.is_a?(Class) ? argument : argument.to_s.presence.try(:constantize)
21
+ raise("Invalid exception class: #{argument.inspect}") unless klass.is_a?(Class) && (klass == Exception || (klass < Exception))
22
+ @ignored_exception_class_names << klass.name
23
+ end
19
24
  end
20
25
  @ignored_exception_class_names.uniq!
21
26
  nil
@@ -25,6 +30,10 @@ class MultipleDevicesLogger
25
30
  (@ignored_exception_class_names || []).map(&:constantize)
26
31
  end
27
32
 
33
+ def ignored_exceptions_procs
34
+ @ignored_exceptions_procs || []
35
+ end
36
+
28
37
  end
29
38
 
30
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiple_devices_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport