console 1.17.4 → 1.19.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: e68f107945b1831b98497a3a7d6a251b030788dfb0f85e212af7da334816f791
4
+ data.tar.gz: 0460616df8b87571a01eba8d41cdfa2c30ae2efb4c7847c322273cc1de8d74fd
5
5
  SHA512:
6
- metadata.gz: b118601c16e8a70d0e654aca81d67f0130113a38c926fc931c2d9904b68946e02dfc76af1a7f7804954391ce0600f46ec6897c5416c3a22cdd1a64a2e5d6a798
7
- data.tar.gz: b32ed9872c022cda4d7cfe2d1e754a8015021c7765cca971052b814cc4f50fd5a069c6fc7f50eda680e6576625f95c91c265f52aab8fc6a78c3e1813bc7391f0
6
+ metadata.gz: 9d7f4c0af841a44c643e24dec336bb1a71642fe292fe204382282e6ef1766a6fe6ec4390486c6e9b3bc6d841b5d603739711ed14848fc4024f6d9c2b169e2e09
7
+ data.tar.gz: 65399cb6f4c81c5bbe67a746797fa37a96d8a01f1b540abdb01cccad73ea174439a2c27131db84fa2ee80b6860a69150ed77a19e9d3a298cc22dc1e6ed4a97bf
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ module Console
7
+ module Adapter
8
+ end
9
+ end
@@ -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.19.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.19.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-08-02 00:00:00.000000000 Z
47
47
  dependencies:
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: fiber-local
@@ -165,6 +165,7 @@ extra_rdoc_files: []
165
165
  files:
166
166
  - bake/console.rb
167
167
  - lib/console.rb
168
+ - lib/console/adapter.rb
168
169
  - lib/console/buffer.rb
169
170
  - lib/console/capture.rb
170
171
  - lib/console/clock.rb
@@ -179,6 +180,7 @@ files:
179
180
  - lib/console/output.rb
180
181
  - lib/console/output/default.rb
181
182
  - lib/console/output/json.rb
183
+ - lib/console/output/null.rb
182
184
  - lib/console/output/sensitive.rb
183
185
  - lib/console/output/split.rb
184
186
  - lib/console/output/text.rb
metadata.gz.sig CHANGED
Binary file