helium-console 0.1.7 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d935efaa6d5d2a98d58c2d0cea17911486522ce45bfd00432b089735994ce20
|
4
|
+
data.tar.gz: c86a17fc7b04379249cf491da55086537f7f8983c47758d9b20438495f12039e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab8ca592e31437b6e70cd269cd961b8fc38c3e544b24aa2eecfbddce474ed22ebda4c704849271b847656e22d15b25feb169aedad5593f6267378e211b068bf
|
7
|
+
data.tar.gz: 2915fa426caea028e549e9d55e5a4cb7799ef593cdd706529c9eac5bc582a841bdaaa67fb1480917df0543286a0d7743f5eb13b813b92ad4193eab207d49a378
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-rake
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
NewCops: enable
|
7
|
+
|
8
|
+
Style/LambdaCall:
|
9
|
+
EnforcedStyle: braces
|
10
|
+
|
11
|
+
Layout/CaseIndentation:
|
12
|
+
EnforcedStyle: end
|
13
|
+
IndentOneStep: true
|
14
|
+
|
15
|
+
Style/NestedParenthesizedCalls:
|
16
|
+
AllowedMethods:
|
17
|
+
- be
|
18
|
+
- be_a
|
19
|
+
- be_an
|
20
|
+
- be_between
|
21
|
+
- be_falsey
|
22
|
+
- be_kind_of
|
23
|
+
- be_instance_of
|
24
|
+
- be_truthy
|
25
|
+
- be_within
|
26
|
+
- eq
|
27
|
+
- eql
|
28
|
+
- end_with
|
29
|
+
- expect
|
30
|
+
- include
|
31
|
+
- match
|
32
|
+
- raise_error
|
33
|
+
- respond_to
|
34
|
+
- start_with
|
35
|
+
|
36
|
+
Layout/EndAlignment:
|
37
|
+
EnforcedStyleAlignWith: start_of_line
|
38
|
+
|
39
|
+
Layout/MultilineMethodCallIndentation:
|
40
|
+
EnforcedStyle: indented
|
41
|
+
|
42
|
+
Style/Documentation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Bundler/OrderedGems:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/EmptyMethod:
|
49
|
+
EnforcedStyle: expanded
|
50
|
+
|
51
|
+
Metrics/BlockLength:
|
52
|
+
IgnoredMethods:
|
53
|
+
- define_formatter_for
|
54
|
+
Exclude:
|
55
|
+
- "*.gemspec"
|
56
|
+
- "spec/**/*_spec.rb"
|
57
|
+
|
58
|
+
Metrics/MethodLength:
|
59
|
+
Max: 15
|
60
|
+
|
61
|
+
RSpec/MultipleExpectations:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/NumericPredicate:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/EachWithObject:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
|
data/Gemfile
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in helium-console.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
8
|
+
gem 'rake', '~> 12.0'
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'ffaker'
|
11
|
+
gem 'byebug'
|
12
|
+
gem 'rubocop', require: false
|
13
|
+
gem 'rubocop-rspec', require: false
|
14
|
+
gem 'rubocop-rake', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
helium-console (0.1.
|
4
|
+
helium-console (0.1.11)
|
5
5
|
colorize
|
6
6
|
pry
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
ast (2.4.2)
|
11
12
|
byebug (11.1.3)
|
12
13
|
coderay (1.1.3)
|
13
14
|
colorize (0.8.1)
|
14
15
|
diff-lcs (1.4.4)
|
15
16
|
ffaker (2.18.0)
|
16
17
|
method_source (1.0.0)
|
18
|
+
parallel (1.20.1)
|
19
|
+
parser (3.0.2.0)
|
20
|
+
ast (~> 2.4.1)
|
17
21
|
pry (0.14.1)
|
18
22
|
coderay (~> 1.1)
|
19
23
|
method_source (~> 1.0)
|
24
|
+
rainbow (3.0.0)
|
20
25
|
rake (12.3.3)
|
26
|
+
regexp_parser (2.1.1)
|
27
|
+
rexml (3.2.5)
|
21
28
|
rspec (3.10.0)
|
22
29
|
rspec-core (~> 3.10.0)
|
23
30
|
rspec-expectations (~> 3.10.0)
|
@@ -31,6 +38,24 @@ GEM
|
|
31
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
39
|
rspec-support (~> 3.10.0)
|
33
40
|
rspec-support (3.10.2)
|
41
|
+
rubocop (1.19.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.0.0.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml
|
47
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.10.0)
|
51
|
+
parser (>= 3.0.1.1)
|
52
|
+
rubocop-rake (0.6.0)
|
53
|
+
rubocop (~> 1.0)
|
54
|
+
rubocop-rspec (2.4.0)
|
55
|
+
rubocop (~> 1.0)
|
56
|
+
rubocop-ast (>= 1.1.0)
|
57
|
+
ruby-progressbar (1.11.0)
|
58
|
+
unicode-display_width (2.0.0)
|
34
59
|
|
35
60
|
PLATFORMS
|
36
61
|
ruby
|
@@ -41,6 +66,9 @@ DEPENDENCIES
|
|
41
66
|
helium-console!
|
42
67
|
rake (~> 12.0)
|
43
68
|
rspec (~> 3.0)
|
69
|
+
rubocop
|
70
|
+
rubocop-rake
|
71
|
+
rubocop-rspec
|
44
72
|
|
45
73
|
BUNDLED WITH
|
46
74
|
2.1.4
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'helium/console'
|
5
6
|
|
6
7
|
require 'byebug'
|
7
8
|
require 'ffaker'
|
8
9
|
|
9
|
-
class A
|
10
|
-
def initialize(a)
|
11
|
-
@a = a
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
10
|
Pry.start
|
data/helium-console.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/helium/console/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'helium-console'
|
5
7
|
spec.version = Helium::Console::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['Stanislaw Klajn']
|
9
|
+
spec.email = ['sklajn@gmail.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'Collection of tools for smooth integration with console'
|
12
|
+
spec.homepage = 'https://github.com/helium-rb/console'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
13
15
|
|
14
|
-
spec.metadata[
|
15
|
-
spec.metadata[
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/helium-rb/console'
|
16
18
|
|
17
19
|
# Specify which files should be added to the gem when it is released.
|
18
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
23
|
end
|
22
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
spec.add_dependency 'colorize'
|
28
|
+
spec.add_dependency 'pry'
|
27
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
module Formatters
|
@@ -7,7 +9,7 @@ module Helium
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def call(string)
|
10
|
-
string.lines.map {|line| ' ' * @indent + line }.join
|
12
|
+
string.lines.map { |line| ' ' * @indent + line }.join
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
module Formatters
|
4
6
|
class MaxLines
|
5
|
-
ELLIPSES = "
|
7
|
+
ELLIPSES = '..."'
|
6
8
|
|
7
9
|
def initialize(max_lines:, max_width:, ellipses:)
|
8
10
|
@max_lines = max_lines
|
@@ -16,7 +18,7 @@ module Helium
|
|
16
18
|
lines = string.lines.first(@max_lines)
|
17
19
|
last_line = lines.pop
|
18
20
|
lines << last_line.chars.first(@max_width - @ellipses.length).join + @ellipses
|
19
|
-
lines.join
|
21
|
+
lines.join
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
module Formatters
|
@@ -11,8 +13,8 @@ module Helium
|
|
11
13
|
result = string.lines.flat_map do |line|
|
12
14
|
line.chomp.chars.each_slice(@max_width).map(&:join)
|
13
15
|
end
|
14
|
-
result = result.join(
|
15
|
-
result +=
|
16
|
+
result = result.join("\n")
|
17
|
+
result += "\n" if string.end_with?("\n")
|
16
18
|
result
|
17
19
|
end
|
18
20
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Helium
|
3
4
|
class Console
|
@@ -6,8 +7,8 @@ module Helium
|
|
6
7
|
def self.get(type)
|
7
8
|
require "helium/console/formatters/overflow/#{type}"
|
8
9
|
const_get(type.to_s.split('_').map(&:capitalize).join)
|
9
|
-
rescue
|
10
|
-
raise Error
|
10
|
+
rescue LoadError
|
11
|
+
raise Error, "Unknown overflow option: #{type}"
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
class ColorPrinter < Pry::ColorPrinter
|
@@ -10,11 +12,14 @@ module Helium
|
|
10
12
|
|
11
13
|
def pp(object)
|
12
14
|
formatted = Helium::Console.format(object)
|
13
|
-
|
14
|
-
|
15
|
+
output << "\n" if object.is_a? Registry::Element::LazyStringEvaluator
|
16
|
+
formatted.lines.each do |line|
|
17
|
+
output << "#{line.chomp}\n"
|
18
|
+
end
|
19
|
+
output << "\n"
|
15
20
|
end
|
16
21
|
|
17
|
-
::Pry.config.print =
|
22
|
+
::Pry.config.print = method(:default)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Helium
|
2
4
|
class Console
|
3
5
|
define_formatter_for Array do
|
4
6
|
def call
|
5
|
-
return
|
6
|
-
return
|
7
|
+
return '[]' if object.none?
|
8
|
+
return inline_with_truncation if force_inline?
|
7
9
|
|
8
|
-
|
10
|
+
inline_without_truncation || format_as_table
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
13
|
+
def simple?
|
12
14
|
object.none?
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
private
|
16
18
|
|
17
19
|
def format_as_table
|
18
20
|
table = Table.new(runner: ' ', format_keys: false)
|
@@ -20,51 +22,54 @@ module Helium
|
|
20
22
|
table.row(light_black("[#{index}]:"), element)
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
format(table)
|
26
|
-
|
27
|
-
|
25
|
+
yield_lines do |y|
|
26
|
+
y << '['
|
27
|
+
format(table).lines.each { |line| y << line }
|
28
|
+
y << ']'
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
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 - 4)
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
new_joined
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
"[ #{formatted.compact.join(' | ')} ]"
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
def inline_without_truncation
|
44
|
+
return unless object.all? { |element| Helium::Console.simple? element }
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
formatted = formatted_elements.inject([]) do |joined, element|
|
47
|
+
joined = [*joined, element]
|
48
|
+
break if too_long?(joined, max_width: max_width - 4)
|
46
49
|
|
47
|
-
|
48
|
-
joined = [" ", joined, trunc, " "].compact.join if joined
|
49
|
-
["[", joined, "]"].compact.join
|
50
|
-
else
|
51
|
-
"[...(#{object.length})]"
|
50
|
+
joined
|
52
51
|
end
|
52
|
+
|
53
|
+
"[ #{formatted.join(' | ')} ]" 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
|
53
59
|
end
|
54
60
|
|
55
|
-
def
|
56
|
-
|
61
|
+
def formatted_elements(**options)
|
62
|
+
object.each.lazy.map { |element| format_nested(element, **options) }
|
63
|
+
end
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
def trunc_message(count, all_truncated: false)
|
66
|
+
return if count < 1
|
60
67
|
|
61
|
-
|
62
|
-
|
68
|
+
"(#{count} #{all_truncated ? 'elements' : 'more'})"
|
69
|
+
end
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
joined = " #{joined} " if joined
|
67
|
-
["[", joined, "]"].compact.join
|
71
|
+
def object_size
|
72
|
+
@object_size ||= object.size
|
68
73
|
end
|
69
74
|
|
70
75
|
def force_inline?
|