helium-console 0.1.7 → 0.1.11
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/.rubocop.yml +70 -0
- data/Gemfile +10 -5
- data/Gemfile.lock +29 -1
- data/Rakefile +5 -3
- data/bin/console +3 -8
- data/helium-console.gemspec +16 -14
- data/lib/helium/console/formatters/indent.rb +3 -1
- data/lib/helium/console/formatters/max_lines.rb +4 -2
- data/lib/helium/console/formatters/overflow/wrap.rb +4 -2
- data/lib/helium/console/formatters/overflow.rb +3 -2
- data/lib/helium/console/printer.rb +8 -3
- data/lib/helium/console/registry/array.rb +42 -37
- data/lib/helium/console/registry/booleans.rb +2 -0
- data/lib/helium/console/registry/date.rb +11 -0
- data/lib/helium/console/registry/hash.rb +54 -43
- data/lib/helium/console/registry/module.rb +12 -4
- data/lib/helium/console/registry/nil.rb +2 -0
- data/lib/helium/console/registry/numeric.rb +2 -0
- data/lib/helium/console/registry/object.rb +30 -38
- data/lib/helium/console/registry/pathname.rb +11 -0
- data/lib/helium/console/registry/set.rb +80 -0
- data/lib/helium/console/registry/string.rb +6 -4
- data/lib/helium/console/registry/symbol.rb +3 -1
- data/lib/helium/console/registry/table.rb +42 -36
- data/lib/helium/console/registry/time.rb +11 -0
- data/lib/helium/console/registry.rb +47 -14
- data/lib/helium/console/table.rb +3 -2
- data/lib/helium/console/version.rb +3 -1
- data/lib/helium/console.rb +25 -19
- metadata +11 -6
@@ -1,14 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'colorized_string'
|
2
4
|
|
3
5
|
module Helium
|
4
6
|
class Console
|
5
7
|
class Registry
|
6
8
|
class Element
|
9
|
+
class LazyStringEvaluator
|
10
|
+
def initialize(&block)
|
11
|
+
@lines = Enumerator.new { |y| block.(y) }
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :lines
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
lines.to_a.join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
7
21
|
def initialize(object, **options)
|
8
22
|
@object = object
|
9
23
|
@options = options
|
10
24
|
end
|
11
25
|
|
26
|
+
def call
|
27
|
+
end
|
28
|
+
|
12
29
|
attr_reader :object, :options
|
13
30
|
|
14
31
|
def format_nested(other_object, **options)
|
@@ -23,28 +40,41 @@ module Helium
|
|
23
40
|
Helium::Console.format_string(string, **options)
|
24
41
|
end
|
25
42
|
|
26
|
-
def simple?
|
27
|
-
Helium::Console.simple?(object)
|
28
|
-
end
|
29
|
-
|
30
|
-
def is_simple
|
43
|
+
def simple?
|
31
44
|
false
|
32
45
|
end
|
33
46
|
|
34
47
|
def method_missing(name, *args)
|
35
48
|
return @options[name] if @options.key?(name)
|
36
|
-
if ColorizedString.colors.include?(name)
|
37
|
-
|
38
|
-
end
|
49
|
+
return ColorizedString.new(*args).colorize(name) if ColorizedString.colors.include?(name)
|
50
|
+
|
39
51
|
super
|
40
52
|
end
|
41
53
|
|
54
|
+
def respond_to_missing?(name, private = false)
|
55
|
+
@options.key?(name) || ColorizedString.colors.include?(name) || super
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def nested_objects
|
61
|
+
[]
|
62
|
+
end
|
63
|
+
|
42
64
|
def nested_opts(new_options, increase_level: true)
|
43
65
|
new_options = options.merge(new_options)
|
44
66
|
new_options[:level] += 1 if increase_level
|
45
|
-
new_options[:ignore_objects]
|
67
|
+
new_options[:ignore_objects] = nested_objects
|
46
68
|
new_options
|
47
69
|
end
|
70
|
+
|
71
|
+
def length_of(string)
|
72
|
+
ColorizedString.new(string).uncolorize.length
|
73
|
+
end
|
74
|
+
|
75
|
+
def yield_lines(&block)
|
76
|
+
LazyStringEvaluator.new(&block)
|
77
|
+
end
|
48
78
|
end
|
49
79
|
|
50
80
|
def add(klass, &handler)
|
@@ -58,17 +88,20 @@ module Helium
|
|
58
88
|
end
|
59
89
|
|
60
90
|
def handler_for(object, **options)
|
61
|
-
object.class.ancestors.
|
62
|
-
|
91
|
+
element_class = object.class.ancestors.find do |ancestor|
|
92
|
+
break handlers[ancestor] if handlers.key?(ancestor)
|
93
|
+
break handlers[ancestor.name] if handlers.key?(ancestor.name)
|
63
94
|
end
|
64
|
-
|
95
|
+
return unless element_class
|
96
|
+
|
97
|
+
element_class.new(object, **options)
|
65
98
|
end
|
66
99
|
|
67
|
-
|
100
|
+
private
|
68
101
|
|
69
102
|
def handlers
|
70
103
|
@handlers ||= {}
|
71
104
|
end
|
72
105
|
end
|
73
106
|
end
|
74
|
-
end
|
107
|
+
end
|
data/lib/helium/console/table.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
class Table
|
4
|
-
|
5
|
-
def initialize(runner: "|", after_key: " ", format_keys: true)
|
6
|
+
def initialize(runner: '|', after_key: ' ', format_keys: true)
|
6
7
|
@runner = runner
|
7
8
|
@after_key = after_key
|
8
9
|
@format_keys = format_keys
|
data/lib/helium/console.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require "helium/console/formatters/indent"
|
5
|
-
require "helium/console/formatters/overflow"
|
6
|
-
require "helium/console/formatters/max_lines"
|
7
|
-
require "helium/console/table"
|
8
|
-
require "helium/console/registry"
|
3
|
+
require 'pry'
|
9
4
|
|
10
|
-
require
|
5
|
+
require 'helium/console/version'
|
6
|
+
require 'helium/console/formatters/indent'
|
7
|
+
require 'helium/console/formatters/overflow'
|
8
|
+
require 'helium/console/formatters/max_lines'
|
9
|
+
require 'helium/console/table'
|
10
|
+
require 'helium/console/registry'
|
11
|
+
|
12
|
+
require 'helium/console/printer'
|
11
13
|
|
12
14
|
module Helium
|
13
15
|
class Console
|
@@ -19,7 +21,7 @@ module Helium
|
|
19
21
|
FalseClass,
|
20
22
|
TrueClass,
|
21
23
|
Symbol
|
22
|
-
]
|
24
|
+
].freeze
|
23
25
|
|
24
26
|
class << self
|
25
27
|
def instance
|
@@ -31,6 +33,10 @@ module Helium
|
|
31
33
|
|
32
34
|
instance.public_send(name, *args, &block)
|
33
35
|
end
|
36
|
+
|
37
|
+
def respond_to_missing?(name, private = false)
|
38
|
+
instance.respond_to?(name) || super
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
def initialize(registry:)
|
@@ -39,12 +45,12 @@ module Helium
|
|
39
45
|
|
40
46
|
def format(object, **options)
|
41
47
|
options = default_options.merge(options)
|
42
|
-
return
|
48
|
+
return '(...)' if options[:ignore_objects].include?(object.object_id)
|
43
49
|
|
44
50
|
handler = registry.handler_for(object, **options)
|
45
51
|
|
46
52
|
if handler
|
47
|
-
handler.
|
53
|
+
handler.()
|
48
54
|
else
|
49
55
|
format(object.inspect, **options)
|
50
56
|
end
|
@@ -59,8 +65,8 @@ module Helium
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def simple?(object)
|
62
|
-
SIMPLE_OBJECTS.any? {|simple_obj_class| object.is_a? simple_obj_class } ||
|
63
|
-
registry.handler_for(object).
|
68
|
+
SIMPLE_OBJECTS.any? { |simple_obj_class| object.is_a? simple_obj_class } ||
|
69
|
+
registry.handler_for(object).simple?
|
64
70
|
end
|
65
71
|
|
66
72
|
def default_options
|
@@ -69,11 +75,11 @@ module Helium
|
|
69
75
|
indent: 0,
|
70
76
|
max_width: `tput cols`.chomp.to_i,
|
71
77
|
level: 1,
|
72
|
-
ignore_objects: []
|
78
|
+
ignore_objects: []
|
73
79
|
}
|
74
80
|
end
|
75
81
|
|
76
|
-
def format_string(string, ellipses:
|
82
|
+
def format_string(string, ellipses: '...', **options)
|
77
83
|
options = default_options.merge(options)
|
78
84
|
|
79
85
|
formatters = [
|
@@ -86,17 +92,17 @@ module Helium
|
|
86
92
|
)
|
87
93
|
]
|
88
94
|
|
89
|
-
formatters.inject(string) do |
|
90
|
-
formatter.
|
95
|
+
formatters.inject(string) do |str, formatter|
|
96
|
+
formatter.(str)
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
|
100
|
+
private
|
95
101
|
|
96
102
|
attr_reader :registry
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
100
|
-
Dir.glob(File.join(File.dirname(__FILE__),
|
106
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'console', 'registry', '**/*.rb')).sort.each do |file|
|
101
107
|
require file
|
102
108
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
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.11
|
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-
|
11
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
50
51
|
- ".travis.yml"
|
51
52
|
- CODE_OF_CONDUCT.md
|
52
53
|
- Gemfile
|
@@ -66,14 +67,18 @@ files:
|
|
66
67
|
- lib/helium/console/registry.rb
|
67
68
|
- lib/helium/console/registry/array.rb
|
68
69
|
- lib/helium/console/registry/booleans.rb
|
70
|
+
- lib/helium/console/registry/date.rb
|
69
71
|
- lib/helium/console/registry/hash.rb
|
70
72
|
- lib/helium/console/registry/module.rb
|
71
73
|
- lib/helium/console/registry/nil.rb
|
72
74
|
- lib/helium/console/registry/numeric.rb
|
73
75
|
- lib/helium/console/registry/object.rb
|
76
|
+
- lib/helium/console/registry/pathname.rb
|
77
|
+
- lib/helium/console/registry/set.rb
|
74
78
|
- lib/helium/console/registry/string.rb
|
75
79
|
- lib/helium/console/registry/symbol.rb
|
76
80
|
- lib/helium/console/registry/table.rb
|
81
|
+
- lib/helium/console/registry/time.rb
|
77
82
|
- lib/helium/console/table.rb
|
78
83
|
- lib/helium/console/version.rb
|
79
84
|
homepage: https://github.com/helium-rb/console
|
@@ -90,14 +95,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
95
|
requirements:
|
91
96
|
- - ">="
|
92
97
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2.
|
98
|
+
version: 2.5.0
|
94
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
100
|
requirements:
|
96
101
|
- - ">="
|
97
102
|
- !ruby/object:Gem::Version
|
98
103
|
version: '0'
|
99
104
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.1.4
|
101
106
|
signing_key:
|
102
107
|
specification_version: 4
|
103
108
|
summary: Collection of tools for smooth integration with console
|