helium-console 0.1.3 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39304bf103e7e4754ebecc7160a6e2890a555d89b89113b13d5f9605cb5945f6
4
- data.tar.gz: 71b94ce843df7d8a8a42e3e53a24e879918e576f138faeec3bd06adaa485abd1
3
+ metadata.gz: 2ab396ea29a8624295988320add6f5e930e63189df18d760f5a5d7b940757564
4
+ data.tar.gz: 67585b90c765f5c21085d142f09177062e09b7aaea8adab81405cfd78909f04f
5
5
  SHA512:
6
- metadata.gz: b74e6a99292aefa68f2a44cd9f06eb1d64752ece9cda15b75b73e0d5fdee75109081d6a3a95d5c3c0bb4afab6c5c04ebd590e45ca76cf5949b0e37ab89a28064
7
- data.tar.gz: 6b4e951d05b8f76784f4e556c5555ce9f7db0b48ff3f673c8ead7ecb79054ce11da121cea4b0cbfff1984245a8c07746f0e34c22c6a77a0e7c8257e6a73fc8a0
6
+ metadata.gz: 5f8c86fb6604d3be3a7c0de4485875da9be8b2b2ab0f62a39678cee552d55c4d6cb296d10803ca0b1962ada3e9b490525f5e05cff9c1905311afa27df6db4472
7
+ data.tar.gz: a960dc8a18594015a44d5fd83469869e96f8d33cae658c7a825a9fc45c73d53ce06e6386a187a3387ae6d9c9a0cf50cfc0495250ee122dbb109ae9d14ea8110b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- helium-console (0.1.3)
4
+ helium-console (0.1.7)
5
5
  colorize
6
6
  pry
7
7
 
@@ -67,7 +67,6 @@ module Helium
67
67
  {
68
68
  overflow: :wrap,
69
69
  indent: 0,
70
- max_lines: nil,
71
70
  max_width: `tput cols`.chomp.to_i,
72
71
  level: 1,
73
72
  ignore_objects: [],
@@ -66,7 +66,7 @@ module Helium
66
66
  end
67
67
 
68
68
  def force_inline?
69
- (max_lines && max_lines < 5) || level > 2
69
+ level > 2
70
70
  end
71
71
 
72
72
  def all_symbol?
@@ -0,0 +1,16 @@
1
+ module Helium
2
+ class Console
3
+ define_formatter_for Module do
4
+ def call
5
+ light_yellow(object.name || anonymus_text)
6
+ end
7
+
8
+ private
9
+
10
+ def anonymus_text
11
+ closest = object.ancestors.find(&:name).name
12
+ "(anonymous #{closest})"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -16,9 +16,9 @@ module Helium
16
16
  end
17
17
 
18
18
  [
19
- "#{light_black('#')} #{light_yellow(object.class.name)} instance",
20
- format(table, **options),
21
- ].join($/)
19
+ table_header,
20
+ format(table),
21
+ ].reject(&:empty?).join($/)
22
22
  end
23
23
 
24
24
  def format_inline_with_truncation
@@ -27,13 +27,12 @@ module Helium
27
27
 
28
28
  def format_inline_with_no_truncation
29
29
  joined = nil
30
- one_complex = false
31
30
 
32
31
  object.each do |key, value|
33
32
  return unless simple?(value)
34
33
 
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)
34
+ formatted_key = format(key, level: 3, max_with: 15)
35
+ formatted_value = format(value, level: 3, max_width: 15)
37
36
  formatted = "#{formatted_key} => #{formatted_value}"
38
37
 
39
38
  joined = [joined, formatted].compact.join(", ")
@@ -44,8 +43,23 @@ module Helium
44
43
  ["{", joined, "}"].compact.join
45
44
  end
46
45
 
46
+ def table_header
47
+ type = case object
48
+ when Class then :class
49
+ when Module then :module
50
+ else :instance
51
+ end
52
+ klass = type == :instance ? object.class : object
53
+ klass_name = klass.name
54
+ if !klass_name
55
+ named_ancestor = klass.ancestors.find(&:name)
56
+ klass_name = ['anonymous', named_ancestor&.name].compact.join(" ")
57
+ end
58
+ "#{light_black('#')} #{light_yellow(klass_name)} #{type}"
59
+ end
60
+
47
61
  def force_inline?
48
- (max_lines && max_lines < 5) || level > 2
62
+ level > 2
49
63
  end
50
64
 
51
65
  def all_symbol?
@@ -2,17 +2,20 @@ module Helium
2
2
  class Console
3
3
  define_formatter_for String do
4
4
  def call
5
- light_green(Helium::Console.format_string(
5
+ formatted = Helium::Console.format_string(
6
6
  object.dump.gsub('\n', "\n"),
7
7
  max_width: max_width,
8
8
  max_lines: max_lines,
9
9
  overflow: overflow,
10
10
  ellipses: "...\""
11
- ))
11
+ )
12
+
13
+ formatted.lines
14
+ .map { |line| light_green(line) }
15
+ .join
12
16
  end
13
17
 
14
18
  def max_lines
15
- return options[:max_lines] if options[:max_lines]
16
19
  case level
17
20
  when 1 then nil
18
21
  when 2 then 3
@@ -2,17 +2,20 @@ module Helium
2
2
  class Console
3
3
  define_formatter_for Table do
4
4
  def call
5
- formatted_values.join($/)
5
+ [
6
+ *formatted_values,
7
+ truncation,
8
+ ].compact.join($/)
6
9
  end
7
10
 
8
11
  def formatted_values
9
- object.rows.flat_map do |key, value|
10
- formatted_value = format_nested(value, max_width: max_value_width)
12
+ rows.flat_map do |key, value, options = {}|
13
+ formatted_value = format_nested(value, max_width: max_value_width, **options)
11
14
 
12
15
  formatted_value.lines.map.with_index do |line, index|
13
16
  [
14
17
  object.runner,
15
- index.zero? ? format_key(key).rjust(key_width) : " " * key_width,
18
+ index.zero? ? rjust(format_key(key), key_width) : " " * key_width,
16
19
  index.zero? ? object.after_key : " " * length_of(object.after_key),
17
20
  line.chomp,
18
21
  ].join
@@ -20,8 +23,18 @@ module Helium
20
23
  end
21
24
  end
22
25
 
26
+ def truncation
27
+ return unless object.rows.length > rows.length
28
+
29
+ [
30
+ object.runner,
31
+ light_black("(#{object.rows.length - rows.length} more)")
32
+ ].join
33
+ end
34
+
35
+
23
36
  def key_width
24
- @key_width ||= object.rows
37
+ @key_width ||= rows
25
38
  .map(&:first)
26
39
  .map(&method(:format_key))
27
40
  .map(&method(:length_of))
@@ -33,8 +46,11 @@ module Helium
33
46
  end
34
47
 
35
48
  def format_key(key)
36
- return key unless object.format_keys
37
- format(key, max_width: 15, level: 3)
49
+ object.format_keys ? format(key, max_width: 15, level: 3) : key
50
+ end
51
+
52
+ def rjust(string, width)
53
+ " " * (width - length_of(string)) + string
38
54
  end
39
55
 
40
56
  def length_of(string)
@@ -44,6 +60,16 @@ module Helium
44
60
  string.length
45
61
  end
46
62
  end
63
+
64
+ def rows
65
+ @rows ||= case level
66
+ when 1 then object.rows
67
+ when 2
68
+ object.rows.count < 10 ? object.rows : object.rows.first(9)
69
+ else
70
+ object.rows.count < 3 ? object.rows : object.rows.first(2)
71
+ end
72
+ end
47
73
  end
48
74
  end
49
75
  end
@@ -10,8 +10,8 @@ module Helium
10
10
 
11
11
  attr_reader :runner, :after_key, :format_keys
12
12
 
13
- def row(key, value)
14
- rows << [key, value]
13
+ def row(key, value, **options)
14
+ rows << [key, value, options]
15
15
  end
16
16
 
17
17
  def rows
@@ -1,5 +1,5 @@
1
1
  module Helium
2
2
  class Console
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.7"
4
4
  end
5
5
  end
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.3
4
+ version: 0.1.7
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-06 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -67,6 +67,7 @@ files:
67
67
  - lib/helium/console/registry/array.rb
68
68
  - lib/helium/console/registry/booleans.rb
69
69
  - lib/helium/console/registry/hash.rb
70
+ - lib/helium/console/registry/module.rb
70
71
  - lib/helium/console/registry/nil.rb
71
72
  - lib/helium/console/registry/numeric.rb
72
73
  - lib/helium/console/registry/object.rb