helium-console 0.1.9 → 0.1.10
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/lib/helium/console/registry/date.rb +11 -0
- data/lib/helium/console/registry/pathname.rb +11 -0
- data/lib/helium/console/registry/set.rb +80 -0
- data/lib/helium/console/registry/table.rb +1 -1
- data/lib/helium/console/registry/time.rb +11 -0
- data/lib/helium/console/registry.rb +1 -0
- 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: 2775258ea31537dc27077753497d8c6fef2d34f31e6470c17574cd30395675e9
|
4
|
+
data.tar.gz: eafd3659c58654fc6566359f52093c928d7ecfc4bab9c23df74330f814760c6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a18002a4319bb7154810167feb4888ab5199034f001262614d291725623a856fd0a18fea8c362573fb049b823b10753a928bc3401fefcda8be66258f3420bb39
|
7
|
+
data.tar.gz: 56b961dcbfab3a0b39041abba71a36e90166cb7f409f9ea54d3957b2c147ba304e5c35d6c1dcb5c0415e9b0d3f5ea71bbdfb14494ca08a15526b5e43dfa2a89b
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Helium
|
4
|
+
class Console
|
5
|
+
define_formatter_for Set do
|
6
|
+
def call
|
7
|
+
return "#{light_magenta('Set:')} #{red 'empty'}" if object.none?
|
8
|
+
return inline_with_truncation if force_inline?
|
9
|
+
|
10
|
+
inline_without_truncation || format_as_table
|
11
|
+
end
|
12
|
+
|
13
|
+
def simple?
|
14
|
+
object.none?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def format_as_table
|
20
|
+
table = Table.new(runner: '', format_keys: false)
|
21
|
+
object.each do |element|
|
22
|
+
table.row(light_magenta('-'), element)
|
23
|
+
end
|
24
|
+
|
25
|
+
[
|
26
|
+
light_magenta('Set: {'),
|
27
|
+
format(table),
|
28
|
+
light_magenta('}')
|
29
|
+
].join("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def inline_with_truncation
|
33
|
+
formatted = formatted_elements.with_index.inject([]) do |joined, (element, index)|
|
34
|
+
new_joined = [*joined[0..-2], element, trunc_message(object_size - index - 1, all_truncated: index.zero?)]
|
35
|
+
break joined if too_long?(new_joined, max_width: max_width - 9)
|
36
|
+
|
37
|
+
new_joined
|
38
|
+
end
|
39
|
+
|
40
|
+
"#{light_magenta('Set: {')} #{formatted.join(light_magenta(' | '))} #{light_magenta('}')}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def inline_without_truncation
|
44
|
+
return unless object.all? { |element| Helium::Console.simple? element }
|
45
|
+
|
46
|
+
formatted = formatted_elements.inject([]) do |joined, element|
|
47
|
+
joined = [*joined, element]
|
48
|
+
break if too_long?(joined, max_width: max_width - 4)
|
49
|
+
|
50
|
+
joined
|
51
|
+
end
|
52
|
+
|
53
|
+
"#{light_magenta('Set: {')} #{formatted.join(light_magenta(' | '))} #{light_magenta('}')}" unless formatted.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
def too_long?(object, max_width:)
|
57
|
+
string = object.respond_to?(:join) ? object.join(' | ') : object
|
58
|
+
length_of(string) > max_width - 4
|
59
|
+
end
|
60
|
+
|
61
|
+
def formatted_elements(**options)
|
62
|
+
object.sort.each.lazy.map { |element| format_nested(element, **options) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def trunc_message(count, all_truncated: false)
|
66
|
+
return if count < 1
|
67
|
+
|
68
|
+
light_black "(#{count} #{all_truncated ? 'elements' : 'more'})"
|
69
|
+
end
|
70
|
+
|
71
|
+
def object_size
|
72
|
+
@object_size ||= object.size
|
73
|
+
end
|
74
|
+
|
75
|
+
def force_inline?
|
76
|
+
level > 2
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -68,6 +68,7 @@ module Helium
|
|
68
68
|
def handler_for(object, **options)
|
69
69
|
element_class = object.class.ancestors.find do |ancestor|
|
70
70
|
break handlers[ancestor] if handlers.key?(ancestor)
|
71
|
+
break handlers[ancestor.name] if handlers.key?(ancestor.name)
|
71
72
|
end
|
72
73
|
return unless element_class
|
73
74
|
|
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.10
|
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-08-
|
11
|
+
date: 2021-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -67,14 +67,18 @@ files:
|
|
67
67
|
- lib/helium/console/registry.rb
|
68
68
|
- lib/helium/console/registry/array.rb
|
69
69
|
- lib/helium/console/registry/booleans.rb
|
70
|
+
- lib/helium/console/registry/date.rb
|
70
71
|
- lib/helium/console/registry/hash.rb
|
71
72
|
- lib/helium/console/registry/module.rb
|
72
73
|
- lib/helium/console/registry/nil.rb
|
73
74
|
- lib/helium/console/registry/numeric.rb
|
74
75
|
- lib/helium/console/registry/object.rb
|
76
|
+
- lib/helium/console/registry/pathname.rb
|
77
|
+
- lib/helium/console/registry/set.rb
|
75
78
|
- lib/helium/console/registry/string.rb
|
76
79
|
- lib/helium/console/registry/symbol.rb
|
77
80
|
- lib/helium/console/registry/table.rb
|
81
|
+
- lib/helium/console/registry/time.rb
|
78
82
|
- lib/helium/console/table.rb
|
79
83
|
- lib/helium/console/version.rb
|
80
84
|
homepage: https://github.com/helium-rb/console
|