object_inspector 0.8.2 → 0.10.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 +4 -4
- data/README.md +152 -95
- data/lib/object_inspector/formatters/base_formatter.rb +1 -1
- data/lib/object_inspector/formatters/combining_formatter.rb +5 -0
- data/lib/object_inspector/inspector.rb +5 -4
- data/lib/object_inspector/inspectors_helper.rb +11 -1
- data/lib/object_inspector/version.rb +1 -1
- data/lib/object_inspector.rb +1 -1
- 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: 1468942ef1aa4a276a2138a904f34329d8b1e9846b58e013c208fbfe4a9113da
|
4
|
+
data.tar.gz: a552ef57ab52b60f208bbe2fceac50f96be25a340cd3854864a5d6a54e3d886f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d02eab73350615584726ada8923bcdea3d428cf61d8e95abf17778b4b76836f828b2c12389dadf1aebe85e369106b4396da1e8501f81fe4e74b44a3031171b8
|
7
|
+
data.tar.gz: 1d044028f4889d0b6bd5615d5f035e19e5bf6ce7e5a30a30ce54a686edb403dd89a826bf8cfd0c4a89781c862af798d4e50ce9a1ed0080012f33a99ec4e477e1
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Object Inspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, issues, info, and/or a name along with an optional, self-definable scope option to represent objects. Great for the console, logging, etc.
|
7
7
|
|
8
|
-
Why? Because object inspection
|
8
|
+
Why? Because object inspection output should be uniform and easy to build, and its output should be easy to read! Consistency improves readability.
|
9
9
|
|
10
10
|
If you'd like to just jump into an example: [Full Example](#full-example).
|
11
11
|
|
@@ -19,11 +19,15 @@ gem "object_inspector"
|
|
19
19
|
|
20
20
|
And then execute:
|
21
21
|
|
22
|
-
|
22
|
+
```sh
|
23
|
+
$ bundle
|
24
|
+
```
|
23
25
|
|
24
26
|
Or install it yourself:
|
25
27
|
|
26
|
-
|
28
|
+
```sh
|
29
|
+
$ gem install object_inspector
|
30
|
+
```
|
27
31
|
|
28
32
|
## Compatibility
|
29
33
|
|
@@ -42,19 +46,19 @@ gem "object_inspector", "0.6.3"
|
|
42
46
|
For Ruby 3.1 support, install object_inspector gem version 0.7.0.
|
43
47
|
|
44
48
|
```ruby
|
45
|
-
gem "object_inspector", "0.
|
49
|
+
gem "object_inspector", "0.7.0"
|
46
50
|
```
|
47
51
|
|
48
52
|
Object Inspector has no other dependencies.
|
49
53
|
|
50
54
|
## Configuration
|
51
55
|
|
52
|
-
Global/default values for Object Inspector can be configured via the ObjectInspector::Configuration object.
|
53
|
-
|
54
|
-
_Note: In a Rails app, the following would go in e.g. `config/initializers/object_inspector.rb`_
|
56
|
+
Global/default values for Object Inspector can be configured via the [ObjectInspector::Configuration] object.
|
55
57
|
|
56
58
|
```ruby
|
57
|
-
#
|
59
|
+
# config/initializers/object_inspector.rb
|
60
|
+
|
61
|
+
# Default values are shown. Customize to your liking.
|
58
62
|
ObjectInspector.configure do |config|
|
59
63
|
config.formatter_class = ObjectInspector::TemplatingFormatter
|
60
64
|
config.inspect_method_prefix = "inspect"
|
@@ -71,7 +75,7 @@ end
|
|
71
75
|
|
72
76
|
## Usage
|
73
77
|
|
74
|
-
|
78
|
+
Pass an object of any type into `ObjectInspector::Inspector.inspect`.
|
75
79
|
|
76
80
|
```ruby
|
77
81
|
class MyObject
|
@@ -83,11 +87,11 @@ end
|
|
83
87
|
MyObject.new.inspect # => "<MyObject>"
|
84
88
|
```
|
85
89
|
|
86
|
-
See
|
90
|
+
See: [Helper Usage](#helper-usage) for simpler usage.
|
87
91
|
|
88
92
|
### Output Customization
|
89
93
|
|
90
|
-
Use the `identification`, `flags`, `info`, and/or `name` options to customize inspect output.
|
94
|
+
Use the `identification`, `flags`, `issues`, `info`, and/or `name` options to customize inspect output.
|
91
95
|
|
92
96
|
```ruby
|
93
97
|
class MyObject
|
@@ -96,15 +100,17 @@ class MyObject
|
|
96
100
|
self,
|
97
101
|
identification: "My Object",
|
98
102
|
flags: "FLAG1 / FLAG2",
|
103
|
+
issues: "ISSUE1",
|
99
104
|
info: "INFO",
|
100
105
|
name: "NAME")
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
104
|
-
MyObject.new.inspect
|
109
|
+
MyObject.new.inspect
|
110
|
+
# => "<My Object(FLAG1 / FLAG2) !!ISSUE1!! INFO :: NAME>"
|
105
111
|
```
|
106
112
|
|
107
|
-
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) as either public or private methods on Object.
|
113
|
+
Or, define `inspect_identification`, `inspect_flags`, `inspect_issues`, `inspect_info`, and/or `inspect_name` (or `display_name`) as either public or private methods on Object.
|
108
114
|
|
109
115
|
```ruby
|
110
116
|
class MyObject
|
@@ -114,11 +120,11 @@ class MyObject
|
|
114
120
|
|
115
121
|
private
|
116
122
|
|
117
|
-
def inspect_identification
|
118
|
-
def inspect_flags
|
119
|
-
def inspect_issues
|
120
|
-
def inspect_info
|
121
|
-
def inspect_name
|
123
|
+
def inspect_identification = "My Object"
|
124
|
+
def inspect_flags = "FLAG1 / FLAG2"
|
125
|
+
def inspect_issues = "ISSUE1 | ISSUE2"
|
126
|
+
def inspect_info = "INFO"
|
127
|
+
def inspect_name = "NAME" # Or: def display_name = "NAME"
|
122
128
|
end
|
123
129
|
|
124
130
|
MyObject.new.inspect
|
@@ -127,7 +133,7 @@ MyObject.new.inspect
|
|
127
133
|
|
128
134
|
## Helper Usage
|
129
135
|
|
130
|
-
To save some typing, include ObjectInspector::InspectHelper into an object and ObjectInspector::Inspector.inspect will be called on `self` automatically.
|
136
|
+
To save some typing, include ObjectInspector::InspectHelper into an object and `ObjectInspector::Inspector.inspect` will be called on `self` automatically.
|
131
137
|
|
132
138
|
```ruby
|
133
139
|
class MyObject
|
@@ -164,17 +170,41 @@ class MyObject
|
|
164
170
|
|
165
171
|
private
|
166
172
|
|
167
|
-
def inspect_identification
|
168
|
-
def inspect_flags
|
169
|
-
def inspect_issues
|
170
|
-
def inspect_info
|
171
|
-
def inspect_name
|
173
|
+
def inspect_identification = "My Object"
|
174
|
+
def inspect_flags = "FLAG1 / FLAG2"
|
175
|
+
def inspect_issues = "ISSUE1 | ISSUE2"
|
176
|
+
def inspect_info = "INFO"
|
177
|
+
def inspect_name = "NAME" # Or: def display_name = "NAME"
|
172
178
|
end
|
173
179
|
|
174
180
|
MyObject.new.inspect
|
175
181
|
# => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
|
176
182
|
```
|
177
183
|
|
184
|
+
### Helper Inclusion
|
185
|
+
|
186
|
+
It may be useful to conditionally include ObjectInspector::InspectorsHelper, as well as other similar methods, via a mix-in.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
module ObjectInspectionBehaviors
|
190
|
+
extend ActiveSupport::Concern
|
191
|
+
|
192
|
+
included do
|
193
|
+
# If you'd like to preserve the original inspect method, here is your
|
194
|
+
# chance to.
|
195
|
+
alias_method :__inspect__, :inspect
|
196
|
+
|
197
|
+
include ObjectInspector::InspectorsHelper
|
198
|
+
end
|
199
|
+
|
200
|
+
# An example of another, similar style of method you may wish to utilize in
|
201
|
+
# this mix-in.
|
202
|
+
def introspect
|
203
|
+
self
|
204
|
+
end
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
178
208
|
## Scopes
|
179
209
|
|
180
210
|
Use the `scope` option to define the scope of the `inspect_*` methods. The supplied value will be wrapped by the ObjectInspector::Scope helper object.
|
@@ -192,15 +222,16 @@ my_object.inspect(scope: <scope_name>)
|
|
192
222
|
|
193
223
|
Options:
|
194
224
|
|
195
|
-
- `:self` (Default)
|
196
|
-
- `:all
|
197
|
-
- `<custom
|
225
|
+
- `:self` (Default)--Is meant to confine object interrogation to self (don't interrogate neighboring objects).
|
226
|
+
- `:all`--Is meant to match on all scopes, regardless of their name.
|
227
|
+
- `<custom>`--Anything else that makes sense for the object to key on.
|
198
228
|
|
199
229
|
```ruby
|
200
230
|
scope = ObjectInspector::Scope.new
|
201
|
-
scope.self?
|
202
|
-
scope.verbose?
|
203
|
-
scope.complex?
|
231
|
+
scope.self? # => true
|
232
|
+
scope.verbose? # => false
|
233
|
+
scope.complex? # => false
|
234
|
+
scope.<anything>? # => false
|
204
235
|
```
|
205
236
|
|
206
237
|
#### Multiple Scope Names
|
@@ -223,8 +254,11 @@ scope = ObjectInspector::Scope.new(:all)
|
|
223
254
|
scope.self? # => true
|
224
255
|
scope.verbose? # => true
|
225
256
|
scope.complex? # => true
|
257
|
+
scope.all? # => true
|
226
258
|
```
|
227
259
|
|
260
|
+
_**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectorsHelper` is equivalent to passing in the "wild card" scope.
|
261
|
+
|
228
262
|
### Scope blocks
|
229
263
|
|
230
264
|
Passing a block to a scope predicate falls back to the out-of-scope placeholder (`*` by default) if the scope does not match.
|
@@ -240,20 +274,19 @@ scope.complex? { "MATCH" } # => "*"
|
|
240
274
|
ObjectInspector::Scope also offers helper methods for uniformly joining inspect elements:
|
241
275
|
|
242
276
|
```ruby
|
243
|
-
join_name
|
244
|
-
join_flags
|
245
|
-
|
277
|
+
join_name # Joins name parts with ` - ` by default
|
278
|
+
join_flags # Joins flags with ` / ` by default
|
279
|
+
join_issues # Joins issues with ` | ` by default
|
280
|
+
join_info # Joins info items with ` | ` by default
|
246
281
|
```
|
247
282
|
|
248
283
|
For example:
|
249
284
|
|
250
285
|
```ruby
|
251
|
-
scope = ObjectInspector::Scope.new(:
|
252
|
-
scope.join_name([1, 2, 3])
|
253
|
-
scope.join_name([1, 2, 3, nil]) # => "1 - 2 - 3"
|
254
|
-
scope.join_flags([1, 2, 3]) # => "1 / 2 / 3"
|
286
|
+
scope = ObjectInspector::Scope.new(:all)
|
287
|
+
scope.join_name([1, 2, 3, nil]) # => "1 - 2 - 3"
|
255
288
|
scope.join_flags([1, 2, 3, nil]) # => "1 / 2 / 3"
|
256
|
-
scope.
|
289
|
+
scope.join_issues([1, 2, 3, nil]) # => "1 | 2 | 3"
|
257
290
|
scope.join_info([1, 2, 3, nil]) # => "1 | 2 | 3"
|
258
291
|
```
|
259
292
|
|
@@ -272,11 +305,11 @@ class MyObject
|
|
272
305
|
end
|
273
306
|
|
274
307
|
def associated_object1
|
275
|
-
|
308
|
+
Data.define(:flags)["AO1_FLAG1"]
|
276
309
|
end
|
277
310
|
|
278
311
|
def associated_object2
|
279
|
-
|
312
|
+
Data.define(:flags)["AO2_FLAG1"]
|
280
313
|
end
|
281
314
|
|
282
315
|
# Or `def inspect_name`
|
@@ -304,8 +337,11 @@ class MyObject
|
|
304
337
|
scope.join_flags(flags)
|
305
338
|
end
|
306
339
|
|
307
|
-
def inspect_issues
|
308
|
-
|
340
|
+
def inspect_issues(scope:)
|
341
|
+
scope.join_issues([
|
342
|
+
"I1",
|
343
|
+
scope.verbose? { "VI2" },
|
344
|
+
])
|
309
345
|
end
|
310
346
|
|
311
347
|
def inspect_info(scope:)
|
@@ -319,37 +355,43 @@ end
|
|
319
355
|
|
320
356
|
my_object = MyObject.new("Name")
|
321
357
|
|
358
|
+
my_object.inspect
|
359
|
+
# => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | * :: Name>"
|
360
|
+
|
361
|
+
my_object.inspect(scope: :self)
|
362
|
+
# => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | * :: Name>"
|
363
|
+
|
322
364
|
my_object.inspect(scope: :complex)
|
323
|
-
# => "<MyObject[
|
365
|
+
# => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>"
|
324
366
|
|
325
367
|
my_object.inspect(scope: :verbose)
|
326
|
-
# => "<MyObject[
|
368
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Verbose Info :: Name>"
|
327
369
|
|
328
370
|
my_object.inspect(scope: %i[self complex verbose])
|
329
|
-
# => "<MyObject[
|
371
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
330
372
|
|
331
373
|
my_object.inspect(scope: :all)
|
332
|
-
# => "<MyObject[
|
374
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
333
375
|
|
334
|
-
my_object.inspect
|
335
|
-
# => "<MyObject[
|
376
|
+
my_object.inspect! # 👀 Same as passing in `scope: :all`
|
377
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
336
378
|
|
337
379
|
ObjectInspector.configuration.default_scope = :complex
|
338
380
|
my_object.inspect
|
339
|
-
# => "<MyObject[
|
381
|
+
# => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>"
|
340
382
|
|
341
383
|
ObjectInspector.configuration.default_scope = %i[self complex verbose]
|
342
384
|
my_object.inspect
|
343
|
-
# => "<MyObject[
|
385
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
344
386
|
|
345
387
|
ObjectInspector.configuration.default_scope = :all
|
346
388
|
my_object.inspect
|
347
|
-
# => "<MyObject[
|
389
|
+
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
348
390
|
```
|
349
391
|
|
350
392
|
## Wrapped Objects
|
351
393
|
|
352
|
-
If the Object being inspected wraps another object
|
394
|
+
If the Object being inspected wraps another object--i.e. defines #to_model and #to_model returns an object other than self--the inspect output will re-inspect the wrapped object. The wrapper points to the wrapped object with an arrow (⇨).
|
353
395
|
|
354
396
|
```ruby
|
355
397
|
class MyWrapperObject
|
@@ -361,7 +403,8 @@ class MyWrapperObject
|
|
361
403
|
|
362
404
|
private
|
363
405
|
|
364
|
-
def inspect_flags
|
406
|
+
def inspect_flags = "WRAPPER_FLAG1"
|
407
|
+
def inspect_issues(scope:) = scope.complex? { "CI1" }
|
365
408
|
end
|
366
409
|
|
367
410
|
class MyWrappedObject
|
@@ -369,12 +412,16 @@ class MyWrappedObject
|
|
369
412
|
|
370
413
|
private
|
371
414
|
|
372
|
-
def inspect_flags
|
373
|
-
def inspect_info
|
415
|
+
def inspect_flags = "FLAG1 / FLAG2"
|
416
|
+
def inspect_info = "INFO"
|
417
|
+
def inspect_issues(scope:) = scope.complex? { "CI1" }
|
374
418
|
end
|
375
419
|
|
376
420
|
MyWrapperObject.new.inspect
|
377
|
-
# => "<MyWrapperObject(WRAPPER_FLAG1)
|
421
|
+
# => "<MyWrapperObject(WRAPPER_FLAG1) !!*!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!*!! INFO>"
|
422
|
+
|
423
|
+
MyWrapperObject.new.inspect!
|
424
|
+
# => "<MyWrapperObject(WRAPPER_FLAG1) !!CI1!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!CI1!! INFO>"
|
378
425
|
```
|
379
426
|
|
380
427
|
This feature is recursive.
|
@@ -424,10 +471,10 @@ class MyWrappedObject
|
|
424
471
|
|
425
472
|
private
|
426
473
|
|
427
|
-
def inspect_flags
|
428
|
-
def inspect_info
|
429
|
-
def inspect_issues
|
430
|
-
def inspect_name
|
474
|
+
def inspect_flags = "FLAG1"
|
475
|
+
def inspect_info = "INFO"
|
476
|
+
def inspect_issues = "ISSUE1"
|
477
|
+
def inspect_name = "NAME"
|
431
478
|
end
|
432
479
|
|
433
480
|
MyDelegatingWrapperObject.new(MyWrappedObject.new).inspect
|
@@ -442,10 +489,10 @@ When passed as an option (as opposed to being called via an Object-defined metho
|
|
442
489
|
class MyObject
|
443
490
|
include ObjectInspector::InspectorsHelper
|
444
491
|
|
445
|
-
def my_method1
|
446
|
-
def my_method2
|
492
|
+
def my_method1 = "Result1"
|
493
|
+
def my_method2 = "Result2"
|
447
494
|
|
448
|
-
def inspect_info
|
495
|
+
def inspect_info = :my_method2
|
449
496
|
end
|
450
497
|
|
451
498
|
MyObject.new.inspect(info: "my_method1") # => "<MyObject my_method1>"
|
@@ -461,17 +508,18 @@ Pass `nil` to any inspect method type to not display it:
|
|
461
508
|
class MyObject
|
462
509
|
include ObjectInspector::InspectorsHelper
|
463
510
|
|
464
|
-
def inspect_identification
|
465
|
-
def inspect_info
|
466
|
-
def inspect_flags
|
467
|
-
def inspect_issues
|
511
|
+
def inspect_identification = "My Object"
|
512
|
+
def inspect_info = "INFO"
|
513
|
+
def inspect_flags = "FLAG1"
|
514
|
+
def inspect_issues = "ISSUE1"
|
515
|
+
def inspect_name = "NAME"
|
468
516
|
end
|
469
517
|
|
470
518
|
MyObject.new.inspect
|
471
|
-
# => "<My Object(FLAG1) !!ISSUE1!! INFO>"
|
519
|
+
# => "<My Object(FLAG1) !!ISSUE1!! INFO :: NAME>"
|
472
520
|
MyObject.new.inspect(info: nil, flags: nil, issues: nil)
|
473
|
-
# => "<My Object>"
|
474
|
-
MyObject.new.inspect(identification: nil, info: nil, flags: nil, issues: nil)
|
521
|
+
# => "<My Object :: NAME>"
|
522
|
+
MyObject.new.inspect(identification: nil, info: nil, flags: nil, issues: nil, name: nil)
|
475
523
|
# => "<MyObject>"
|
476
524
|
```
|
477
525
|
|
@@ -490,11 +538,12 @@ class MyObject
|
|
490
538
|
include ObjectInspector::InspectorsHelper
|
491
539
|
|
492
540
|
def inspect
|
493
|
-
super(
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
541
|
+
super(
|
542
|
+
formatter: MyCustomFormatter,
|
543
|
+
identification: "IDENTIFICATION",
|
544
|
+
flags: "FLAG1 / FLAG2",
|
545
|
+
info: "INFO",
|
546
|
+
name: "NAME")
|
498
547
|
end
|
499
548
|
end
|
500
549
|
|
@@ -529,10 +578,10 @@ class MyObject
|
|
529
578
|
identify(:my_method1, :my_method2)
|
530
579
|
end
|
531
580
|
|
532
|
-
def inspect_flags
|
533
|
-
def inspect_issues
|
534
|
-
def inspect_info
|
535
|
-
def inspect_name
|
581
|
+
def inspect_flags = "FLAG1 / FLAG2"
|
582
|
+
def inspect_issues = "ISSUE1 | ISSUE2"
|
583
|
+
def inspect_info = "INFO"
|
584
|
+
def inspect_name = "NAME"
|
536
585
|
end
|
537
586
|
|
538
587
|
MyObject.new.inspect
|
@@ -543,51 +592,59 @@ MyObject.new.inspect
|
|
543
592
|
|
544
593
|
### Benchmarking Object Inspector
|
545
594
|
|
546
|
-
ObjectInspetor is ~
|
595
|
+
ObjectInspetor is ~2.75x slower than Ruby's default inspect, in Ruby v3.4.
|
547
596
|
|
548
597
|
Performance of Object Inspector can be tested by playing the [Object Inspector Benchmarking Script](https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/object_inspector.rb) in the IRB console for this gem.
|
549
598
|
|
550
599
|
```ruby
|
551
600
|
load "script/benchmarking/object_inspector.rb"
|
601
|
+
# Reporting for: Ruby v3.4.2
|
602
|
+
#
|
603
|
+
# == Averaged =============================================================
|
604
|
+
# ...
|
605
|
+
#
|
552
606
|
# Comparison:
|
553
|
-
# Ruby:
|
554
|
-
# ObjectInspector::Inspector:
|
607
|
+
# Ruby: 58957.2 i/s
|
608
|
+
# ObjectInspector::Inspector: 21416.6 i/s - 2.75x slower
|
609
|
+
# == Done
|
555
610
|
```
|
556
611
|
|
557
612
|
### Benchmarking Formatters
|
558
613
|
|
559
|
-
[ObjectInspector::TemplatingFormatter]
|
614
|
+
[ObjectInspector::TemplatingFormatter]--which is the default Formatter--outperforms [ObjectInspector::CombiningFormatter] by about 30% on average.
|
560
615
|
|
561
616
|
Performance of Formatters can be tested by playing the [Formatters Benchmarking Scripts](https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/formatters.rb) in the IRB console for this gem.
|
562
617
|
|
563
618
|
```ruby
|
564
619
|
load "script/benchmarking/formatters.rb"
|
620
|
+
# Reporting for: Ruby v3.4.2
|
621
|
+
#
|
565
622
|
# == Averaged =============================================================
|
566
623
|
# ...
|
567
624
|
#
|
568
625
|
# Comparison:
|
569
|
-
# ObjectInspector::TemplatingFormatter:
|
570
|
-
# ObjectInspector::CombiningFormatter:
|
571
|
-
#
|
626
|
+
# ObjectInspector::TemplatingFormatter: 65856.3 i/s
|
627
|
+
# ObjectInspector::CombiningFormatter: 60920.0 i/s - 1.13x slower
|
572
628
|
# == Done
|
573
629
|
```
|
574
630
|
|
575
631
|
#### Benchmarking Custom Formatters
|
576
632
|
|
577
|
-
Custom Formatters may be similarly gauged for comparison by
|
633
|
+
Custom Formatters may be similarly gauged for comparison by putting them into a constant `CUSTOM_FORMATTER_CLASSES` before loading the script in the IRB console for this gem.
|
578
634
|
|
579
635
|
```ruby
|
580
|
-
|
636
|
+
CUSTOM_FORMATTER_CLASSES = [MyCustomFormatter]
|
581
637
|
|
582
|
-
|
638
|
+
load "script/benchmarking/formatters.rb"
|
639
|
+
# Reporting for: Ruby v3.4.2
|
640
|
+
#
|
583
641
|
# == Averaged =============================================================
|
584
642
|
# ...
|
585
643
|
#
|
586
644
|
# Comparison:
|
587
|
-
# MyCustomFormatter:
|
588
|
-
# ObjectInspector::TemplatingFormatter:
|
589
|
-
# ObjectInspector::CombiningFormatter:
|
590
|
-
#
|
645
|
+
# MyCustomFormatter: 74227.7 i/s
|
646
|
+
# ObjectInspector::TemplatingFormatter: 66148.5 i/s - 1.12x slower
|
647
|
+
# ObjectInspector::CombiningFormatter: 63289.7 i/s - 1.17x slower
|
591
648
|
# == Done
|
592
649
|
```
|
593
650
|
|
@@ -601,13 +658,13 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
601
658
|
|
602
659
|
To test this gem:
|
603
660
|
|
604
|
-
```
|
661
|
+
```sh
|
605
662
|
rake
|
606
663
|
```
|
607
664
|
|
608
665
|
#### Linters
|
609
666
|
|
610
|
-
```
|
667
|
+
```sh
|
611
668
|
rubocop
|
612
669
|
|
613
670
|
reek
|
@@ -38,6 +38,7 @@ class ObjectInspector::CombiningFormatter < ObjectInspector::BaseFormatter
|
|
38
38
|
[
|
39
39
|
build_identification_string,
|
40
40
|
build_flags_string,
|
41
|
+
build_issues_string,
|
41
42
|
build_info_string,
|
42
43
|
build_name_string,
|
43
44
|
].compact
|
@@ -51,6 +52,10 @@ class ObjectInspector::CombiningFormatter < ObjectInspector::BaseFormatter
|
|
51
52
|
"(#{flags.to_s.upcase})" if flags
|
52
53
|
end
|
53
54
|
|
55
|
+
def build_issues_string
|
56
|
+
" !!#{issues.to_s.upcase}!!" if issues
|
57
|
+
end
|
58
|
+
|
54
59
|
def build_info_string
|
55
60
|
" #{info}" if info
|
56
61
|
end
|
@@ -36,7 +36,7 @@ class ObjectInspector::Inspector
|
|
36
36
|
**kwargs)
|
37
37
|
@object = object
|
38
38
|
@scope = ObjectInspector::Conversions.Scope(scope)
|
39
|
-
@
|
39
|
+
@formatter_class = formatter
|
40
40
|
@kwargs = kwargs
|
41
41
|
end
|
42
42
|
|
@@ -47,7 +47,8 @@ class ObjectInspector::Inspector
|
|
47
47
|
formatter.call
|
48
48
|
end
|
49
49
|
|
50
|
-
# Generate the inspect String for the wrapped object, if
|
50
|
+
# Generate the inspect String for the wrapped object, if `self` is a wrapper
|
51
|
+
# object.
|
51
52
|
#
|
52
53
|
# @return [String] if {#object_is_a_wrapper?}
|
53
54
|
# @return [NilClass] if not {#object_is_a_wrapper?}
|
@@ -57,7 +58,7 @@ class ObjectInspector::Inspector
|
|
57
58
|
self.class.inspect(
|
58
59
|
extract_wrapped_object,
|
59
60
|
scope: @scope,
|
60
|
-
formatter: @
|
61
|
+
formatter: @formatter_class,
|
61
62
|
kwargs: @kwargs)
|
62
63
|
end
|
63
64
|
|
@@ -112,7 +113,7 @@ class ObjectInspector::Inspector
|
|
112
113
|
private
|
113
114
|
|
114
115
|
def formatter
|
115
|
-
@
|
116
|
+
@formatter_class.new(self)
|
116
117
|
end
|
117
118
|
|
118
119
|
# @return [String] if `key` is found in {#kwargs} or if {#object} responds to
|
@@ -5,10 +5,20 @@
|
|
5
5
|
# generating the inspection output.
|
6
6
|
module ObjectInspector::InspectorsHelper
|
7
7
|
# Calls {ObjectInspector::Inspector.inspect} on the passed in `object`,
|
8
|
-
# passing
|
8
|
+
# passing through any keyword arguments.
|
9
9
|
#
|
10
10
|
# @return [String]
|
11
11
|
def inspect(object = self, **)
|
12
12
|
ObjectInspector::Inspector.inspect(object, **)
|
13
13
|
end
|
14
|
+
|
15
|
+
# Like {#inspect} but forces scope to `:all`. This (the bang (!) version) is
|
16
|
+
# considered the "more dangerous" version of {#inspect} in the sense that the
|
17
|
+
# `:all` scope may result in additional queries or extra processing--depending
|
18
|
+
# on how the inspect hooks are setup.
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def inspect!(object = self, **)
|
22
|
+
ObjectInspector::Inspector.inspect(object, **, scope: :all)
|
23
|
+
end
|
14
24
|
end
|
data/lib/object_inspector.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul DobbinSchmaltz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: benchmark-ips
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.6.
|
113
|
+
rubygems_version: 3.6.6
|
114
114
|
specification_version: 4
|
115
115
|
summary: Object Inspector builds uniformly formatted inspect output with customizable
|
116
116
|
amounts of detail.
|