pretty_please 0.1.1 → 0.2.0

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: 365d9e2915676455efdca0dd386d189d4df6f7d325e3221b02e111eb8dbc5d9a
4
- data.tar.gz: 33194dec65f5ac364c5b57d52f6ae8e8c52c5fde43a5b74fbbc2c05c52ed7e58
3
+ metadata.gz: 6fb770ff02334614334043c30be8c7b3f52ec56a352a8133c4975c3584ce2ddd
4
+ data.tar.gz: 8bb89b47187675c716ef330b51b499830d03b06850bdb6d06be0e3585c1fd94f
5
5
  SHA512:
6
- metadata.gz: 284a2deff3f55ad2164a3e3129509f6911941ad14c0de62910fab2c95249e3f3537fcebc80d674a62c8a0a3df37b06b012df0f08e6c075468016bdf0912cbb71
7
- data.tar.gz: f50010b485d24b5bd81c168bf9e5bed082283f5473ca4b87d79b9b341928fbe236a9477b57ecb07b654273f37e4262d88877c5b8433a078feea28cdeb2f3d088
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 Pathname, File
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.to_a.sort) { |it| capture { prettify(it) } }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrettyPlease
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  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.1
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-05 00:00:00.000000000 Z
11
+ date: 2025-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dispersion