console 1.34.1 → 1.34.2
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/console/format/safe.rb +34 -42
- data/lib/console/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6602f8f73b2adbead7829f5e9476634f133233c7bbe6c3150392cbd6c3fb61d7
|
4
|
+
data.tar.gz: c954a7b9e8b6aedc3587a7380dbf4b6289ca424865eb22d00cb849afe02b3142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d3e661229a45145fb0e817e4cee61949e15c0684ad49145ad8162f6b11df11329bfde79de66adaf13ecc12478507fcf3e10dc0b9c8d4d2cb9f60a345ee243d
|
7
|
+
data.tar.gz: c8cfe6575c401ac51e2869a97f317f5f8f2aa75cdc6215ce4c880740c7e0224ef053b252f9356eceb1e4c0d83c666945c40815faa61939438a2fd6451a5db629
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/console/format/safe.rb
CHANGED
@@ -17,7 +17,7 @@ module Console
|
|
17
17
|
# @parameter format [JSON] The format to use for serialization.
|
18
18
|
# @parameter limit [Integer] The maximum depth to recurse into objects.
|
19
19
|
# @parameter encoding [Encoding] The encoding to use for strings.
|
20
|
-
def initialize(format: ::JSON, limit:
|
20
|
+
def initialize(format: ::JSON, limit: 12, encoding: ::Encoding::UTF_8)
|
21
21
|
@format = format
|
22
22
|
@limit = limit
|
23
23
|
@encoding = encoding
|
@@ -96,21 +96,6 @@ module Console
|
|
96
96
|
return object
|
97
97
|
end
|
98
98
|
|
99
|
-
# Replace the given object with a safe truncated representation.
|
100
|
-
#
|
101
|
-
# @parameter object [Object] The object to replace.
|
102
|
-
# @returns [String] The replacement string.
|
103
|
-
def replacement_for(object)
|
104
|
-
case object
|
105
|
-
when Array
|
106
|
-
"[...]"
|
107
|
-
when Hash
|
108
|
-
"{...}"
|
109
|
-
else
|
110
|
-
"..."
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
99
|
# Create a new hash with identity comparison.
|
115
100
|
def default_objects
|
116
101
|
Hash.new.compare_by_identity
|
@@ -123,40 +108,47 @@ module Console
|
|
123
108
|
# @parameter objects [Hash] The objects that have already been visited.
|
124
109
|
# @returns [Object] The dumped object as a primitive representation.
|
125
110
|
def safe_dump_recurse(object, limit = @limit, objects = default_objects)
|
126
|
-
if limit <= 0 || objects[object]
|
127
|
-
return replacement_for(object)
|
128
|
-
end
|
129
|
-
|
130
111
|
case object
|
131
112
|
when Hash
|
132
|
-
objects[object]
|
133
|
-
|
134
|
-
|
135
|
-
[
|
136
|
-
|
137
|
-
|
138
|
-
|
113
|
+
if limit <= 0 || objects[object]
|
114
|
+
return "{...}"
|
115
|
+
else
|
116
|
+
objects[object] = true
|
117
|
+
|
118
|
+
return object.to_h do |key, value|
|
119
|
+
[
|
120
|
+
String(key).encode(@encoding, invalid: :replace, undef: :replace),
|
121
|
+
safe_dump_recurse(value, limit - 1, objects)
|
122
|
+
]
|
123
|
+
end
|
139
124
|
end
|
140
125
|
when Array
|
141
|
-
objects[object]
|
142
|
-
|
143
|
-
|
144
|
-
|
126
|
+
if limit <= 0 || objects[object]
|
127
|
+
return "[...]"
|
128
|
+
else
|
129
|
+
objects[object] = true
|
130
|
+
|
131
|
+
return object.map do |value|
|
132
|
+
safe_dump_recurse(value, limit - 1, objects)
|
133
|
+
end
|
145
134
|
end
|
146
135
|
when String
|
147
|
-
object.encode(@encoding, invalid: :replace, undef: :replace)
|
136
|
+
return object.encode(@encoding, invalid: :replace, undef: :replace)
|
148
137
|
when Numeric, TrueClass, FalseClass, NilClass
|
149
|
-
object
|
138
|
+
return object
|
150
139
|
else
|
151
|
-
objects[object]
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
140
|
+
if limit <= 0 || objects[object]
|
141
|
+
return "..."
|
142
|
+
else
|
143
|
+
objects[object] = true
|
144
|
+
|
145
|
+
# We could do something like this but the chance `as_json` will blow up.
|
146
|
+
# We'd need to be extremely careful about it.
|
147
|
+
# if object.respond_to?(:as_json)
|
148
|
+
# safe_dump_recurse(object.as_json, limit - 1, objects)
|
149
|
+
# else
|
150
|
+
return safe_dump_recurse(object.to_s, limit - 1, objects)
|
151
|
+
end
|
160
152
|
end
|
161
153
|
end
|
162
154
|
end
|
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.34.
|
4
|
+
version: 1.34.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
157
|
+
rubygems_version: 3.7.2
|
158
158
|
specification_version: 4
|
159
159
|
summary: Beautiful logging for Ruby.
|
160
160
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|