console 1.17.4 → 1.18.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: 279d68c968f13422584c4b2101ce400373798479884450f4bd6db20783d115e3
4
- data.tar.gz: 4a8df91d11deba88a6fc18f1dd2c09c16676cf32ef045c22aa1e25a942a4ba51
3
+ metadata.gz: b5e54a0a87d6c2ad440476163691fcc67016d8cdabd95f218f0e55db0a311ffd
4
+ data.tar.gz: a1cc36ed4d66731525458abebac6ba9081e68c17524bc32a0125291684b8107b
5
5
  SHA512:
6
- metadata.gz: b118601c16e8a70d0e654aca81d67f0130113a38c926fc931c2d9904b68946e02dfc76af1a7f7804954391ce0600f46ec6897c5416c3a22cdd1a64a2e5d6a798
7
- data.tar.gz: b32ed9872c022cda4d7cfe2d1e754a8015021c7765cca971052b814cc4f50fd5a069c6fc7f50eda680e6576625f95c91c265f52aab8fc6a78c3e1813bc7391f0
6
+ metadata.gz: 864fb845fbdb448f16a7c6b43d024ab5581ad42eb3187efcba046f9feff43f59bdb0164e5fb94fac34bd1387d26742d32395827d9e5d30a158ea8dbc8cd47391
7
+ data.tar.gz: 6af247ea1c0c9df853dfae8de8c651ed487e4ae010d46975586e23a6fc1925cd7a20d27545495cba3e14ea0e8246fc87f88c51acbd226cd10d7ce092338c0efe
checksums.yaml.gz.sig CHANGED
Binary file
@@ -14,12 +14,12 @@ module Console
14
14
  class Filter
15
15
  def self.[] **levels
16
16
  klass = Class.new(self)
17
- min_level, max_level = levels.values.minmax
17
+ minimum_level, maximum_level = levels.values.minmax
18
18
 
19
19
  klass.instance_exec do
20
20
  const_set(:LEVELS, levels.freeze)
21
- const_set(:MINIMUM_LEVEL, min_level)
22
- const_set(:MAXIMUM_LEVEL, max_level)
21
+ const_set(:MINIMUM_LEVEL, minimum_level)
22
+ const_set(:MAXIMUM_LEVEL, maximum_level)
23
23
 
24
24
  levels.each do |name, level|
25
25
  const_set(name.to_s.upcase, level)
@@ -43,7 +43,7 @@ module Console
43
43
  return klass
44
44
  end
45
45
 
46
- def initialize(output, verbose: true, level: self.class::DEFAULT_LEVEL, enabled: nil, **options)
46
+ def initialize(output, verbose: true, level: self.class::DEFAULT_LEVEL, **options)
47
47
  @output = output
48
48
  @verbose = verbose
49
49
  @level = level
@@ -51,10 +51,6 @@ module Console
51
51
  @subjects = {}
52
52
 
53
53
  @options = options
54
-
55
- if enabled
56
- enabled.each{|name| enable(name)}
57
- end
58
54
  end
59
55
 
60
56
  def with(level: @level, verbose: @verbose, **options)
@@ -94,10 +90,20 @@ module Console
94
90
  @level = self.class::MINIMUM_LEVEL - 1
95
91
  end
96
92
 
93
+ def filter(subject, level)
94
+ unless subject.is_a?(Module)
95
+ raise ArgumentError, "Expected a class, got #{subject.inspect}"
96
+ end
97
+
98
+ @subjects[subject] = level
99
+ end
100
+
97
101
  # You can enable and disable logging for classes. This function checks if logging for a given subject is enabled.
98
102
  # @param subject [Object] the subject to check.
99
103
  def enabled?(subject, level = self.class::MINIMUM_LEVEL)
100
- if specific_level = @subjects[subject.class]
104
+ subject = subject.class unless subject.is_a?(Module)
105
+
106
+ if specific_level = @subjects[subject]
101
107
  return level >= specific_level
102
108
  end
103
109
 
@@ -107,19 +113,21 @@ module Console
107
113
  end
108
114
 
109
115
  # Enable specific log level for the given class.
110
- # @parameter name [Class] The class to enable.
116
+ # @parameter name [Module] The class to enable.
111
117
  def enable(subject, level = self.class::MINIMUM_LEVEL)
112
- unless subject.is_a?(Class)
113
- raise ArgumentError, "Expected a class, got #{subject.inspect}"
114
- end
115
-
116
- @subjects[subject] = level
118
+ # Set the filter level of logging for a given subject which passes all log messages:
119
+ filter(subject, level)
117
120
  end
118
121
 
119
- # Disable specific logging for the specific class.
120
- # @parameter name [Class] The class to disable.
121
122
  def disable(subject)
122
- unless subject.is_a?(Class)
123
+ # Set the filter level of the logging for a given subject which filters all log messages:
124
+ filter(subject, self.class::MAXIMUM_LEVEL + 1)
125
+ end
126
+
127
+ # Clear any specific filters for the given class.
128
+ # @parameter name [Module] The class to disable.
129
+ def clear(subject)
130
+ unless subject.is_a?(Module)
123
131
  raise ArgumentError, "Expected a class, got #{subject.inspect}"
124
132
  end
125
133
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ module Console
7
+ module Output
8
+ class Null
9
+ def initialize(...)
10
+ end
11
+
12
+ def call(...)
13
+ # Do nothing.
14
+ end
15
+ end
16
+ end
17
+ end
@@ -7,6 +7,7 @@ require_relative 'output/default'
7
7
  require_relative 'output/json'
8
8
  require_relative 'output/text'
9
9
  require_relative 'output/xterm'
10
+ require_relative 'output/null'
10
11
 
11
12
  module Console
12
13
  module Output
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2022, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.17.4"
7
+ VERSION = "1.18.0"
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.4
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -43,7 +43,7 @@ cert_chain:
43
43
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
44
44
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
45
45
  -----END CERTIFICATE-----
46
- date: 2023-07-19 00:00:00.000000000 Z
46
+ date: 2023-07-21 00:00:00.000000000 Z
47
47
  dependencies:
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: fiber-local
@@ -179,6 +179,7 @@ files:
179
179
  - lib/console/output.rb
180
180
  - lib/console/output/default.rb
181
181
  - lib/console/output/json.rb
182
+ - lib/console/output/null.rb
182
183
  - lib/console/output/sensitive.rb
183
184
  - lib/console/output/split.rb
184
185
  - lib/console/output/text.rb
metadata.gz.sig CHANGED
Binary file