helium-console 0.1.1 → 0.1.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
- data/Gemfile.lock +1 -1
- data/bin/console +6 -0
- data/lib/helium/console.rb +6 -2
- data/lib/helium/console/registry.rb +15 -4
- data/lib/helium/console/registry/array.rb +9 -3
- data/lib/helium/console/registry/booleans.rb +15 -0
- data/lib/helium/console/registry/nil.rb +9 -0
- data/lib/helium/console/registry/numeric.rb +9 -0
- data/lib/helium/console/registry/object.rb +50 -9
- data/lib/helium/console/registry/symbol.rb +9 -0
- data/lib/helium/console/registry/table.rb +1 -1
- data/lib/helium/console/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2672ea42122aee52ae7909753311b9de9bd2c2eb8692447866ed5fdb922692
|
4
|
+
data.tar.gz: aa861ce67edc5c52cafc935bc9f1d4055083b68be88157daef22374786e29980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e60e2768854ffb479b8f10f1cc4e0c54fc9ab9655df4a11c1cef59fe3d9c28d792c836b2e98f02af9f557c2b31e562407942e288adbc32c3d91f2eb3ca8ee186
|
7
|
+
data.tar.gz: bde8f3aef8d9bd208ec740d0f35b60400ab39872b4a5a8fca3a05acb97701fe6603352aac1333556ed791b2e8e10a5397a95ad1a5019d4800116505d8ca03f3c
|
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
data/lib/helium/console.rb
CHANGED
@@ -39,6 +39,8 @@ module Helium
|
|
39
39
|
|
40
40
|
def format(object, **options)
|
41
41
|
options = default_options.merge(options)
|
42
|
+
return "(...)" if options[:ignore_objects].include?(object.object_id)
|
43
|
+
|
42
44
|
handler = registry.handler_for(object, **options)
|
43
45
|
|
44
46
|
if handler
|
@@ -57,7 +59,8 @@ module Helium
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def simple?(object)
|
60
|
-
SIMPLE_OBJECTS.any? {|simple_obj_class| object.is_a? simple_obj_class }
|
62
|
+
SIMPLE_OBJECTS.any? {|simple_obj_class| object.is_a? simple_obj_class } ||
|
63
|
+
registry.handler_for(object).is_simple
|
61
64
|
end
|
62
65
|
|
63
66
|
def default_options
|
@@ -66,7 +69,8 @@ module Helium
|
|
66
69
|
indent: 0,
|
67
70
|
max_lines: nil,
|
68
71
|
max_width: `tput cols`.chomp.to_i,
|
69
|
-
level: 1
|
72
|
+
level: 1,
|
73
|
+
ignore_objects: [],
|
70
74
|
}
|
71
75
|
end
|
72
76
|
|
@@ -9,8 +9,12 @@ module Helium
|
|
9
9
|
|
10
10
|
attr_reader :object, :options
|
11
11
|
|
12
|
-
def
|
13
|
-
Helium::Console.format(
|
12
|
+
def format_nested(other_object, **options)
|
13
|
+
Helium::Console.format(other_object, **nested_opts(options))
|
14
|
+
end
|
15
|
+
|
16
|
+
def format(other_object, **options)
|
17
|
+
Helium::Console.format(other_object, **nested_opts(options, increase_level: false))
|
14
18
|
end
|
15
19
|
|
16
20
|
def format_string(string, **options)
|
@@ -21,13 +25,20 @@ module Helium
|
|
21
25
|
Helium::Console.simple?(object)
|
22
26
|
end
|
23
27
|
|
28
|
+
def is_simple
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
24
32
|
def method_missing(name, *args)
|
25
33
|
return @options[name] if @options.key?(name)
|
26
34
|
super
|
27
35
|
end
|
28
36
|
|
29
|
-
def nested_opts(
|
30
|
-
|
37
|
+
def nested_opts(new_options, increase_level: true)
|
38
|
+
new_options = options.merge(new_options)
|
39
|
+
new_options[:level] += 1 if increase_level
|
40
|
+
new_options[:ignore_objects] << object.object_id
|
41
|
+
new_options
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
@@ -2,10 +2,16 @@ module Helium
|
|
2
2
|
class Console
|
3
3
|
define_formatter_for Array do
|
4
4
|
def call
|
5
|
+
return "[]" if object.none?
|
5
6
|
return format_inline_with_truncation if force_inline?
|
7
|
+
|
6
8
|
format_inline_with_no_truncation || format_as_table
|
7
9
|
end
|
8
10
|
|
11
|
+
def is_simple
|
12
|
+
object.none?
|
13
|
+
end
|
14
|
+
|
9
15
|
private
|
10
16
|
|
11
17
|
def format_as_table
|
@@ -16,7 +22,7 @@ module Helium
|
|
16
22
|
|
17
23
|
[
|
18
24
|
"[",
|
19
|
-
format(table
|
25
|
+
format(table),
|
20
26
|
"]"
|
21
27
|
].join($/)
|
22
28
|
end
|
@@ -27,7 +33,7 @@ module Helium
|
|
27
33
|
total = object.length
|
28
34
|
|
29
35
|
object.each.with_index do |element, index|
|
30
|
-
formatted =
|
36
|
+
formatted = format_nested(element, max_lines: 1, nesting: 1, max_width: 15)
|
31
37
|
|
32
38
|
new_joined = [joined, formatted].compact.join(" | ")
|
33
39
|
new_trunc = (" | (#{total - index - 1} #{index.zero? ? 'elements' : 'more'})" unless index == total - 1)
|
@@ -52,7 +58,7 @@ module Helium
|
|
52
58
|
object.each do |element|
|
53
59
|
return unless simple?(element)
|
54
60
|
|
55
|
-
formatted =
|
61
|
+
formatted = format_nested(element)
|
56
62
|
joined = [joined, formatted].compact.join(" | ")
|
57
63
|
|
58
64
|
return if joined.length > max_width - 4
|
@@ -1,14 +1,55 @@
|
|
1
1
|
module Helium
|
2
2
|
class Console
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
define_formatter_for Object do
|
4
|
+
def call
|
5
|
+
return format_inline_with_truncation if force_inline?
|
6
|
+
format_as_table
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def format_as_table
|
12
|
+
table = Table.new(runner: '| ', after_key: ": ", format_keys: false)
|
13
|
+
|
14
|
+
object.instance_variables.each do |inst|
|
15
|
+
table.row(inst.to_s, object.instance_variable_get(inst))
|
16
|
+
end
|
17
|
+
|
18
|
+
[
|
19
|
+
"# #{object.class.name} instance",
|
20
|
+
format(table, **options),
|
21
|
+
].join($/)
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_inline_with_truncation
|
25
|
+
"#{object.class.name}##{object.object_id.to_s(16)}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_inline_with_no_truncation
|
29
|
+
joined = nil
|
30
|
+
one_complex = false
|
31
|
+
|
32
|
+
object.each do |key, value|
|
33
|
+
return unless simple?(value)
|
34
|
+
|
35
|
+
formatted_key = format(key, max_lines: 1, nesting: 1, max_with: 15)
|
36
|
+
formatted_value = format(value, max_lines: 1, nesting: 1, max_width: 15)
|
37
|
+
formatted = "#{formatted_key} => #{formatted_value}"
|
38
|
+
|
39
|
+
joined = [joined, formatted].compact.join(", ")
|
40
|
+
|
41
|
+
return if joined.length > max_width - 4
|
42
|
+
end
|
43
|
+
joined = " #{joined} " if joined
|
44
|
+
["{", joined, "}"].compact.join
|
45
|
+
end
|
46
|
+
|
47
|
+
def force_inline?
|
48
|
+
(max_lines && max_lines < 5) || level > 2
|
49
|
+
end
|
50
|
+
|
51
|
+
def all_symbol?
|
52
|
+
object.keys.all? { |key| key.is_a? Symbol }
|
12
53
|
end
|
13
54
|
end
|
14
55
|
end
|
@@ -7,7 +7,7 @@ module Helium
|
|
7
7
|
|
8
8
|
def formatted_values
|
9
9
|
object.rows.flat_map do |key, value|
|
10
|
-
formatted_value =
|
10
|
+
formatted_value = format_nested(value, max_width: max_value_width)
|
11
11
|
|
12
12
|
formatted_value.lines.map.with_index do |line, index|
|
13
13
|
[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helium-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislaw Klajn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -51,9 +51,13 @@ files:
|
|
51
51
|
- lib/helium/console/printer.rb
|
52
52
|
- lib/helium/console/registry.rb
|
53
53
|
- lib/helium/console/registry/array.rb
|
54
|
+
- lib/helium/console/registry/booleans.rb
|
54
55
|
- lib/helium/console/registry/hash.rb
|
56
|
+
- lib/helium/console/registry/nil.rb
|
57
|
+
- lib/helium/console/registry/numeric.rb
|
55
58
|
- lib/helium/console/registry/object.rb
|
56
59
|
- lib/helium/console/registry/string.rb
|
60
|
+
- lib/helium/console/registry/symbol.rb
|
57
61
|
- lib/helium/console/registry/table.rb
|
58
62
|
- lib/helium/console/table.rb
|
59
63
|
- lib/helium/console/version.rb
|