object_inspector 0.9.0 → 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 +38 -4
- data/lib/object_inspector/inspector.rb +2 -1
- data/lib/object_inspector/inspectors_helper.rb +11 -1
- data/lib/object_inspector/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: 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
|
|
@@ -181,6 +181,30 @@ MyObject.new.inspect
|
|
181
181
|
# => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
|
182
182
|
```
|
183
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
|
+
|
184
208
|
## Scopes
|
185
209
|
|
186
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.
|
@@ -233,6 +257,8 @@ scope.complex? # => true
|
|
233
257
|
scope.all? # => true
|
234
258
|
```
|
235
259
|
|
260
|
+
_**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectorsHelper` is equivalent to passing in the "wild card" scope.
|
261
|
+
|
236
262
|
### Scope blocks
|
237
263
|
|
238
264
|
Passing a block to a scope predicate falls back to the out-of-scope placeholder (`*` by default) if the scope does not match.
|
@@ -347,6 +373,9 @@ my_object.inspect(scope: %i[self complex verbose])
|
|
347
373
|
my_object.inspect(scope: :all)
|
348
374
|
# => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
|
349
375
|
|
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>"
|
378
|
+
|
350
379
|
ObjectInspector.configuration.default_scope = :complex
|
351
380
|
my_object.inspect
|
352
381
|
# => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>"
|
@@ -375,6 +404,7 @@ class MyWrapperObject
|
|
375
404
|
private
|
376
405
|
|
377
406
|
def inspect_flags = "WRAPPER_FLAG1"
|
407
|
+
def inspect_issues(scope:) = scope.complex? { "CI1" }
|
378
408
|
end
|
379
409
|
|
380
410
|
class MyWrappedObject
|
@@ -384,10 +414,14 @@ class MyWrappedObject
|
|
384
414
|
|
385
415
|
def inspect_flags = "FLAG1 / FLAG2"
|
386
416
|
def inspect_info = "INFO"
|
417
|
+
def inspect_issues(scope:) = scope.complex? { "CI1" }
|
387
418
|
end
|
388
419
|
|
389
420
|
MyWrapperObject.new.inspect
|
390
|
-
# => "<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>"
|
391
425
|
```
|
392
426
|
|
393
427
|
This feature is recursive.
|
@@ -590,13 +624,13 @@ load "script/benchmarking/formatters.rb"
|
|
590
624
|
#
|
591
625
|
# Comparison:
|
592
626
|
# ObjectInspector::TemplatingFormatter: 65856.3 i/s
|
593
|
-
# ObjectInspector::CombiningFormatter: 60920.0 i/s - 1.
|
627
|
+
# ObjectInspector::CombiningFormatter: 60920.0 i/s - 1.13x slower
|
594
628
|
# == Done
|
595
629
|
```
|
596
630
|
|
597
631
|
#### Benchmarking Custom Formatters
|
598
632
|
|
599
|
-
Custom Formatters may be similarly gauged for comparison by putting them into a constant `CUSTOM_FORMATTER_CLASSES` before
|
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.
|
600
634
|
|
601
635
|
```ruby
|
602
636
|
CUSTOM_FORMATTER_CLASSES = [MyCustomFormatter]
|
@@ -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?}
|
@@ -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
|
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
|