console 1.21.0 → 1.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/console/format/safe.rb +98 -0
- data/lib/console/format.rb +18 -0
- data/lib/console/output/json.rb +1 -5
- data/lib/console/serialized/logger.rb +2 -2
- data/lib/console/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +3 -6
- data/lib/console/output/encoder.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9f91e3e103d4d8999923473901b90855e7c8ee5a2f1bf5fa7be4b87a435e0e2
|
4
|
+
data.tar.gz: 78cc14aa29facd5ef1909fc08bcd255d11c251f1075dbe92692f26a249557cbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda52b2ed24d9825905e8e929809d9629ba61755059d7e00ef8ceb693839a191d98647bc13fd2c3a7699f8f664560e4f35c316e21bb9e37c24b8d1265c31dd91
|
7
|
+
data.tar.gz: 22a7f6c0be0617140c608b5063c25d3dd220670afc570860f0cd54fea36f889c3b128d168f9dd6bf92c01c271e335b4d73dfd06cfe918f2360911aa8991fcfba
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2023, by Samuel Williams.
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module Console
|
9
|
+
module Format
|
10
|
+
# This class is used to safely dump objects.
|
11
|
+
# It will attempt to dump the object using the given format, but if it fails, it will generate a safe version of the object.
|
12
|
+
class Safe
|
13
|
+
def initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8)
|
14
|
+
@format = format
|
15
|
+
@limit = limit
|
16
|
+
@encoding = encoding
|
17
|
+
end
|
18
|
+
|
19
|
+
def dump(object)
|
20
|
+
@format.dump(object, @limit)
|
21
|
+
rescue => error
|
22
|
+
@format.dump(safe_dump(object, error))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def default_objects
|
28
|
+
Hash.new.compare_by_identity
|
29
|
+
end
|
30
|
+
|
31
|
+
def safe_dump(object, error)
|
32
|
+
object = safe_dump_recurse(object)
|
33
|
+
|
34
|
+
object[:truncated] = true
|
35
|
+
object[:error] = {
|
36
|
+
class: safe_dump_recurse(error.class.name),
|
37
|
+
message: safe_dump_recurse(error.message),
|
38
|
+
}
|
39
|
+
|
40
|
+
return object
|
41
|
+
end
|
42
|
+
|
43
|
+
def replacement_for(object)
|
44
|
+
case object
|
45
|
+
when Array
|
46
|
+
"[...]"
|
47
|
+
when Hash
|
48
|
+
"{...}"
|
49
|
+
else
|
50
|
+
"..."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# This will recursively generate a safe version of the object.
|
55
|
+
# Nested hashes and arrays will be transformed recursively.
|
56
|
+
# Strings will be encoded with the given encoding.
|
57
|
+
# Primitive values will be returned as-is.
|
58
|
+
# Other values will be converted using `as_json` if available, otherwise `to_s`.
|
59
|
+
def safe_dump_recurse(object, limit = @limit, objects = default_objects)
|
60
|
+
if limit <= 0 || objects[object]
|
61
|
+
return replacement_for(object)
|
62
|
+
end
|
63
|
+
|
64
|
+
case object
|
65
|
+
when Hash
|
66
|
+
objects[object] = true
|
67
|
+
|
68
|
+
object.to_h do |key, value|
|
69
|
+
[
|
70
|
+
String(key).encode(@encoding, invalid: :replace, undef: :replace),
|
71
|
+
safe_dump_recurse(value, limit - 1, objects)
|
72
|
+
]
|
73
|
+
end
|
74
|
+
when Array
|
75
|
+
objects[object] = true
|
76
|
+
|
77
|
+
object.map do |value|
|
78
|
+
safe_dump_recurse(value, limit - 1, objects)
|
79
|
+
end
|
80
|
+
when String
|
81
|
+
object.encode(@encoding, invalid: :replace, undef: :replace)
|
82
|
+
when Numeric, TrueClass, FalseClass, NilClass
|
83
|
+
object
|
84
|
+
else
|
85
|
+
objects[object] = true
|
86
|
+
|
87
|
+
# We could do something like this but the chance `as_json` will blow up.
|
88
|
+
# We'd need to be extremely careful about it.
|
89
|
+
# if object.respond_to?(:as_json)
|
90
|
+
# safe_dump_recurse(object.as_json, limit - 1, objects)
|
91
|
+
# else
|
92
|
+
|
93
|
+
safe_dump_recurse(object.to_s, limit - 1, objects)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2023, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative 'format/safe'
|
7
|
+
|
8
|
+
module Console
|
9
|
+
module Format
|
10
|
+
def self.default
|
11
|
+
Safe.new(format: ::JSON)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_json
|
15
|
+
self.default
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/console/output/json.rb
CHANGED
@@ -4,16 +4,12 @@
|
|
4
4
|
# Copyright, 2021-2022, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative '../serialized/logger'
|
7
|
-
require_relative 'encoder'
|
8
7
|
|
9
8
|
module Console
|
10
9
|
module Output
|
11
10
|
module JSON
|
12
11
|
def self.new(output, **options)
|
13
|
-
|
14
|
-
Output::Encoder.new(
|
15
|
-
Serialized::Logger.new(output, format: ::JSON, **options)
|
16
|
-
)
|
12
|
+
Serialized::Logger.new(output, format: Format.default_json, **options)
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
require_relative '../buffer'
|
7
7
|
require_relative '../filter'
|
8
|
+
require_relative '../format'
|
8
9
|
|
9
10
|
require 'time'
|
10
|
-
require 'json'
|
11
11
|
|
12
12
|
require 'fiber/annotation'
|
13
13
|
|
14
14
|
module Console
|
15
15
|
module Serialized
|
16
16
|
class Logger
|
17
|
-
def initialize(io = $stderr, format:
|
17
|
+
def initialize(io = $stderr, format: Format.default, verbose: false, **options)
|
18
18
|
@io = io
|
19
19
|
@start = Time.now
|
20
20
|
@format = format
|
data/lib/console/version.rb
CHANGED
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.
|
4
|
+
version: 1.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -46,7 +46,7 @@ cert_chain:
|
|
46
46
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
47
47
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
48
48
|
-----END CERTIFICATE-----
|
49
|
-
date: 2023-08-
|
49
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
50
50
|
dependencies:
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: fiber-annotation
|
@@ -95,10 +95,11 @@ files:
|
|
95
95
|
- lib/console/event/progress.rb
|
96
96
|
- lib/console/event/spawn.rb
|
97
97
|
- lib/console/filter.rb
|
98
|
+
- lib/console/format.rb
|
99
|
+
- lib/console/format/safe.rb
|
98
100
|
- lib/console/logger.rb
|
99
101
|
- lib/console/output.rb
|
100
102
|
- lib/console/output/default.rb
|
101
|
-
- lib/console/output/encoder.rb
|
102
103
|
- lib/console/output/json.rb
|
103
104
|
- lib/console/output/null.rb
|
104
105
|
- lib/console/output/sensitive.rb
|
metadata.gz.sig
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
��]�cf�3��^6�/>�5���*?m��N����V��{�/>��ͱ����0������D~����/�/.@��pJ��m��g�
|
5
|
-
yy��3�\nъ���vq�Nt9r:��A�����%d��+
|
6
|
-
���d�o�+?���́�jC�\lj��Ѝ%وӨp��{�tr�R���b�������p��L�xH������XwTV� ��?��Wt�m�^B%���i��-//} ���k cX�^S<��寷��a�I��1����R�=����<��F�unZ�s�M���m��B�vE+��L���ǾI�`�ä��IX����R�`(U�Rf�k�="��Nq�5fh
|
1
|
+
G)Q�f���&5Te����t<��ӗoⰲV��Z��#�o
|
2
|
+
#�*O~��Ѩip&;��N��~����q%�t0�<�d��^m5�V2�fגQ�~t/��e�el�U@��m�lB��zWx+��\2�nτaI{�n*Go��X�(�+5���J$d7�S ���3��~w���5�{`�x�d?";'⹐��Ptпf���t%��
|
3
|
+
NR��=�9�(Z��H'�`xI(2�Gɂa��u�d��V0�p�Y�v��Ews�����'����·���ğ���[�J��bi;q�\N�6�5���Hc|YY�B�o�Lbmp.>{Q-��E
|
@@ -1,40 +0,0 @@
|
|
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 Encoder
|
9
|
-
def initialize(output, encoding = ::Encoding::UTF_8)
|
10
|
-
@output = output
|
11
|
-
@encoding = encoding
|
12
|
-
end
|
13
|
-
|
14
|
-
attr :output
|
15
|
-
|
16
|
-
attr :encoding
|
17
|
-
|
18
|
-
def call(subject = nil, *arguments, **options, &block)
|
19
|
-
subject = encode(subject)
|
20
|
-
arguments = encode(arguments)
|
21
|
-
options = encode(options)
|
22
|
-
|
23
|
-
@output.call(subject, *arguments, **options, &block)
|
24
|
-
end
|
25
|
-
|
26
|
-
def encode(value)
|
27
|
-
case value
|
28
|
-
when String
|
29
|
-
value.encode(@encoding, invalid: :replace, undef: :replace)
|
30
|
-
when Array
|
31
|
-
value.map{|item| encode(item)}
|
32
|
-
when Hash
|
33
|
-
value.transform_values{|item| encode(item)}
|
34
|
-
else
|
35
|
-
value
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|