pretty_please 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pretty_please/prettifier.rb +19 -4
- data/lib/pretty_please/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb770ff02334614334043c30be8c7b3f52ec56a352a8133c4975c3584ce2ddd
|
4
|
+
data.tar.gz: 8bb89b47187675c716ef330b51b499830d03b06850bdb6d06be0e3585c1fd94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeb47b2b68683c32851d0fbc288794548d86d835fd663dfab01483b4005ac8f4b296c4098cba9cca0173acbba157724ea5e2833d4e17873848f343ec0a77a7b2
|
7
|
+
data.tar.gz: 2cdd90b746ef1a4428cc943b537ecb98f0097e4b26ed0c83fba6e9a26fd8bcfdd4d9ecdaa80dcdc994921b945052f854c65dce49f8a805bb28601fada82d89f1
|
@@ -14,6 +14,7 @@ class PrettyPlease::Prettifier
|
|
14
14
|
@max_items = max_items
|
15
15
|
@max_depth = max_depth
|
16
16
|
@indent_bytes = " " * @tab_width
|
17
|
+
@running_depth = 0
|
17
18
|
|
18
19
|
@buffer = +""
|
19
20
|
@lines = 0 # note, this is not reset within a capture
|
@@ -48,7 +49,7 @@ class PrettyPlease::Prettifier
|
|
48
49
|
push object.inspect
|
49
50
|
when Module
|
50
51
|
push object.name
|
51
|
-
when
|
52
|
+
when File, defined?(Pathname) && Pathname
|
52
53
|
push %(#{object.class.name}("#{object.to_path}"))
|
53
54
|
when MatchData, (defined?(Date) && Date), (defined?(DateTime) && DateTime), (defined?(Time) && Time), (defined?(URI) && URI)
|
54
55
|
push %(#{object.class.name}("#{object}"))
|
@@ -78,8 +79,19 @@ class PrettyPlease::Prettifier
|
|
78
79
|
push ")"
|
79
80
|
when defined?(Set) && Set
|
80
81
|
push "Set["
|
81
|
-
map(object
|
82
|
+
map(object) { |it| capture { prettify(it) } }
|
82
83
|
push "]"
|
84
|
+
when defined?(ActiveRecord::Base) && ActiveRecord::Base
|
85
|
+
max_items_before = @max_items
|
86
|
+
@max_items = object.attributes.length
|
87
|
+
|
88
|
+
push "#{object.class.name}("
|
89
|
+
map(object.attributes) do |(key, value)|
|
90
|
+
"#{key}: #{capture { prettify(value) }}"
|
91
|
+
end
|
92
|
+
push ")"
|
93
|
+
|
94
|
+
@max_items = max_items_before
|
83
95
|
else
|
84
96
|
push "#{object.class.name}("
|
85
97
|
map(object.instance_variables) do |name|
|
@@ -98,6 +110,8 @@ class PrettyPlease::Prettifier
|
|
98
110
|
return
|
99
111
|
end
|
100
112
|
|
113
|
+
@running_depth += 1
|
114
|
+
|
101
115
|
return unless object.any?
|
102
116
|
|
103
117
|
length = 0
|
@@ -105,6 +119,7 @@ class PrettyPlease::Prettifier
|
|
105
119
|
|
106
120
|
original_lines = @lines
|
107
121
|
exceeds_max_items = object.length > @max_items
|
122
|
+
current_running_depth = @running_depth
|
108
123
|
|
109
124
|
items = indent do
|
110
125
|
object.take(@max_items).map do |item|
|
@@ -114,7 +129,7 @@ class PrettyPlease::Prettifier
|
|
114
129
|
end
|
115
130
|
end
|
116
131
|
|
117
|
-
if (@lines > original_lines) || (length > @max_width)
|
132
|
+
if (@lines > original_lines) || (length > @max_width) || (@running_depth > current_running_depth)
|
118
133
|
indent do
|
119
134
|
items.each do |item|
|
120
135
|
newline
|
@@ -129,7 +144,7 @@ class PrettyPlease::Prettifier
|
|
129
144
|
end
|
130
145
|
newline
|
131
146
|
|
132
|
-
else
|
147
|
+
else # inline
|
133
148
|
push around_inline
|
134
149
|
push items.join(", ")
|
135
150
|
push ", ..." if exceeds_max_items
|
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.
|
4
|
+
version: 0.2.0
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dispersion
|