pretty_please 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/pretty_please/{inspect.rb → prettifier.rb} +12 -12
- data/lib/pretty_please/version.rb +1 -1
- data/lib/pretty_please.rb +7 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 365d9e2915676455efdca0dd386d189d4df6f7d325e3221b02e111eb8dbc5d9a
|
4
|
+
data.tar.gz: 33194dec65f5ac364c5b57d52f6ae8e8c52c5fde43a5b74fbbc2c05c52ed7e58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284a2deff3f55ad2164a3e3129509f6911941ad14c0de62910fab2c95249e3f3537fcebc80d674a62c8a0a3df37b06b012df0f08e6c075468016bdf0912cbb71
|
7
|
+
data.tar.gz: f50010b485d24b5bd81c168bf9e5bed082283f5473ca4b87d79b9b341928fbe236a9477b57ecb07b654273f37e4262d88877c5b8433a078feea28cdeb2f3d088
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ gem install pretty_please
|
|
25
25
|
|
26
26
|
`PrettyPlease.print(object)` prints the object with ANSI highlighting.
|
27
27
|
|
28
|
-
The `PrettyPlease.
|
28
|
+
The `PrettyPlease.prettify` method provides a structured and human-readable representation of Ruby objects by outputting valid Ruby code.
|
29
29
|
|
30
30
|
It handles a variety of data types including Hashes, Arrays, Sets, Modules, and user-defined objects.
|
31
31
|
|
@@ -34,7 +34,7 @@ It handles a variety of data types including Hashes, Arrays, Sets, Modules, and
|
|
34
34
|
```ruby
|
35
35
|
require "pretty_please"
|
36
36
|
|
37
|
-
puts PrettyPlease.
|
37
|
+
puts PrettyPlease.prettify({ a: 1, b: [2, 3], c: { d: 4 } })
|
38
38
|
```
|
39
39
|
|
40
40
|
**Output:**
|
@@ -49,11 +49,11 @@ puts PrettyPlease.inspect({ a: 1, b: [2, 3], c: { d: 4 } })
|
|
49
49
|
|
50
50
|
**Options:**
|
51
51
|
|
52
|
-
- `object`: (required) – The object to
|
52
|
+
- `object`: (required) – The object to prettify and format.
|
53
53
|
- `tab_width`: 2 (Integer) – The number of spaces (or tabs) per indentation level.
|
54
54
|
- `max_width`: 60 (Integer) – The maximum width before elements are split into multiple lines.
|
55
55
|
- `max_depth`: 5 (Integer) – The maximum depth of nested structures before truncation.
|
56
|
-
- `
|
56
|
+
- `max_items`: 10 (Integer) – The maximum number of instance variables to display for objects.
|
57
57
|
|
58
58
|
### Development
|
59
59
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class PrettyPlease::
|
3
|
+
class PrettyPlease::Prettifier
|
4
4
|
Null = Object.new
|
5
5
|
|
6
6
|
def self.call(object, ...)
|
@@ -22,11 +22,11 @@ class PrettyPlease::Inspect
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def call(object)
|
25
|
-
|
25
|
+
prettify(object)
|
26
26
|
@buffer
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def prettify(object)
|
30
30
|
original_object = @original_object
|
31
31
|
|
32
32
|
if original_object == Null
|
@@ -40,8 +40,8 @@ class PrettyPlease::Inspect
|
|
40
40
|
|
41
41
|
@stack.push(object)
|
42
42
|
|
43
|
-
if object.respond_to?(:
|
44
|
-
object.
|
43
|
+
if object.respond_to?(:pretty_please)
|
44
|
+
object.pretty_please(self)
|
45
45
|
else
|
46
46
|
case object
|
47
47
|
when Symbol, String, Integer, Float, Regexp, Range, Rational, Complex, TrueClass, FalseClass, NilClass
|
@@ -54,7 +54,7 @@ class PrettyPlease::Inspect
|
|
54
54
|
push %(#{object.class.name}("#{object}"))
|
55
55
|
when Array
|
56
56
|
push "["
|
57
|
-
map(object) { |it| capture {
|
57
|
+
map(object) { |it| capture { prettify(it) } }
|
58
58
|
push "]"
|
59
59
|
when Exception
|
60
60
|
push %(#{object.class.name}("#{object.message}"))
|
@@ -63,10 +63,10 @@ class PrettyPlease::Inspect
|
|
63
63
|
map(object, around_inline: " ") do |key, value|
|
64
64
|
case key
|
65
65
|
when Symbol
|
66
|
-
"#{key.name}: #{capture {
|
66
|
+
"#{key.name}: #{capture { prettify(value) }}"
|
67
67
|
else
|
68
|
-
key = capture {
|
69
|
-
value = capture {
|
68
|
+
key = capture { prettify(key) }
|
69
|
+
value = capture { prettify(value) }
|
70
70
|
"#{key} => #{value}"
|
71
71
|
end
|
72
72
|
end
|
@@ -74,16 +74,16 @@ class PrettyPlease::Inspect
|
|
74
74
|
when Struct, defined?(Data) && Data
|
75
75
|
push "#{object.class.name}("
|
76
76
|
items = object.members.map { |key| [key, object.__send__(key)] }
|
77
|
-
map(items) { |key, value| "#{key}: #{capture {
|
77
|
+
map(items) { |key, value| "#{key}: #{capture { prettify(value) }}" }
|
78
78
|
push ")"
|
79
79
|
when defined?(Set) && Set
|
80
80
|
push "Set["
|
81
|
-
map(object.to_a.sort) { |it| capture {
|
81
|
+
map(object.to_a.sort) { |it| capture { prettify(it) } }
|
82
82
|
push "]"
|
83
83
|
else
|
84
84
|
push "#{object.class.name}("
|
85
85
|
map(object.instance_variables) do |name|
|
86
|
-
"#{name} = #{capture {
|
86
|
+
"#{name} = #{capture { prettify(object.instance_variable_get(name)) }}"
|
87
87
|
end
|
88
88
|
push ")"
|
89
89
|
end
|
data/lib/pretty_please.rb
CHANGED
@@ -4,13 +4,18 @@ require "pretty_please/version"
|
|
4
4
|
require "dispersion"
|
5
5
|
|
6
6
|
module PrettyPlease
|
7
|
-
autoload :
|
7
|
+
autoload :Prettifier, "pretty_please/prettifier"
|
8
8
|
|
9
9
|
def self.print(object)
|
10
10
|
puts Dispersion.ansi(inspect(object))
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.inspect(...)
|
14
|
-
|
14
|
+
warn "PrettyPlease.inspect is deprecated. Use PrettyPlease.prettify instead."
|
15
|
+
prettify(...)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.prettify(...)
|
19
|
+
Prettifier::(...)
|
15
20
|
end
|
16
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_please
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
- Marco Roth
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dispersion
|
@@ -35,7 +35,7 @@ files:
|
|
35
35
|
- LICENSE.txt
|
36
36
|
- README.md
|
37
37
|
- lib/pretty_please.rb
|
38
|
-
- lib/pretty_please/
|
38
|
+
- lib/pretty_please/prettifier.rb
|
39
39
|
- lib/pretty_please/version.rb
|
40
40
|
homepage: https://github.com/joeldrapper/pretty_please
|
41
41
|
licenses:
|