object_inspector 0.10.0 → 1.1.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: 1468942ef1aa4a276a2138a904f34329d8b1e9846b58e013c208fbfe4a9113da
4
- data.tar.gz: a552ef57ab52b60f208bbe2fceac50f96be25a340cd3854864a5d6a54e3d886f
3
+ metadata.gz: 1a5678d0a60ea94fd380f64bac99e4c0f8e5f1a6752597ce934b2687a87d5f57
4
+ data.tar.gz: ca234feb9aa4dadd78fe1672f1bcbd897f6717597ab246d4b275140fd31de760
5
5
  SHA512:
6
- metadata.gz: 2d02eab73350615584726ada8923bcdea3d428cf61d8e95abf17778b4b76836f828b2c12389dadf1aebe85e369106b4396da1e8501f81fe4e74b44a3031171b8
7
- data.tar.gz: 1d044028f4889d0b6bd5615d5f035e19e5bf6ce7e5a30a30ce54a686edb403dd89a826bf8cfd0c4a89781c862af798d4e50ce9a1ed0080012f33a99ec4e477e1
6
+ metadata.gz: 3585d51c146f4013022e2c2cad959580643f92efd843461f06432f42f406f0a71d6f45e47671c288036d46a94ce4b9f754b37ef446d5fa1590922afbcab23ad4
7
+ data.tar.gz: f1d439874733a0596d63efe69da6eb95df1b8562b3321f14c468448d26a00fd22ee8e90febaf234cd11f9ebd1a9181bc68ba3c29156264ecdd770f4ebd663c08
data/README.md CHANGED
@@ -60,12 +60,13 @@ Global/default values for Object Inspector can be configured via the [ObjectInsp
60
60
 
61
61
  # Default values are shown. Customize to your liking.
62
62
  ObjectInspector.configure do |config|
63
+ config.enabled = true
63
64
  config.formatter_class = ObjectInspector::TemplatingFormatter
64
65
  config.inspect_method_prefix = "inspect"
65
66
  config.default_scope = ObjectInspector::Scope.new(:self)
66
67
  config.wild_card_scope = "all"
67
68
  config.out_of_scope_placeholder = "*"
68
- config.presenter_inspect_flags = " ⇨ "
69
+ config.presented_object_separator = " ⇨ "
69
70
  config.name_separator = " - "
70
71
  config.flags_separator = " / "
71
72
  config.issues_separator = " | "
@@ -75,48 +76,26 @@ end
75
76
 
76
77
  ## Usage
77
78
 
78
- Pass an object of any type into `ObjectInspector::Inspector.inspect`.
79
+ Including `ObjectInspector::InspectBehaviors` into an object will cause `ObjectInspector::Inspector.inspect` to be called on `self` automatically.
79
80
 
80
81
  ```ruby
81
82
  class MyObject
82
- def inspect
83
- ObjectInspector::Inspector.inspect(self)
84
- end
83
+ include ObjectInspector::InspectBehaviors
85
84
  end
86
85
 
87
- MyObject.new.inspect # => "<MyObject>"
88
- ```
89
-
90
- See: [Helper Usage](#helper-usage) for simpler usage.
91
-
92
- ### Output Customization
86
+ MyObject.new.inspect # =>
87
+ "<MyObject>"
93
88
 
94
- Use the `identification`, `flags`, `issues`, `info`, and/or `name` options to customize inspect output.
95
-
96
- ```ruby
97
- class MyObject
98
- def inspect
99
- ObjectInspector::Inspector.inspect(
100
- self,
101
- identification: "My Object",
102
- flags: "FLAG1 / FLAG2",
103
- issues: "ISSUE1",
104
- info: "INFO",
105
- name: "NAME")
106
- end
107
- end
108
-
109
- MyObject.new.inspect
110
- # => "<My Object(FLAG1 / FLAG2) !!ISSUE1!! INFO :: NAME>"
89
+ # NOTE: IRB's Pretty Print processor calls `inspect` and unwraps the quotes:
90
+ MyObject.new # =>
91
+ <MyObject>
111
92
  ```
112
93
 
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.
94
+ Build out the inspect String by defining any of: `inspect_identification`, `inspect_flags`, `inspect_issues`, `inspect_info`, and `inspect_name` (or `display_name`).
114
95
 
115
96
  ```ruby
116
97
  class MyObject
117
- def inspect
118
- ObjectInspector::Inspector.inspect(self)
119
- end
98
+ include ObjectInspector::InspectBehaviors
120
99
 
121
100
  private
122
101
 
@@ -127,79 +106,21 @@ class MyObject
127
106
  def inspect_name = "NAME" # Or: def display_name = "NAME"
128
107
  end
129
108
 
130
- MyObject.new.inspect
131
- # => "<My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
109
+ MyObject.new # =>
110
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
132
111
  ```
133
112
 
134
- ## Helper Usage
135
-
136
- To save some typing, include ObjectInspector::InspectHelper into an object and `ObjectInspector::Inspector.inspect` will be called on `self` automatically.
137
-
138
- ```ruby
139
- class MyObject
140
- include ObjectInspector::InspectorsHelper
141
- end
142
-
143
- MyObject.new.inspect # => "<MyObject>"
144
- ```
113
+ ### Customizing `ObjectInspector::InspectBehaviors`
145
114
 
146
- To access the ObjectInspector::Inspector's options via the helper, call into `super`.
147
-
148
- ```ruby
149
- class MyObject
150
- include ObjectInspector::InspectorsHelper
151
-
152
- def inspect
153
- super(identification: "My Object",
154
- flags: "FLAG1",
155
- issues: "ISSUE1 | ISSUE2",
156
- info: "INFO",
157
- name: "NAME")
158
- end
159
- end
160
-
161
- MyObject.new.inspect
162
- # => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
163
- ```
164
-
165
- Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) in Object.
166
-
167
- ```ruby
168
- class MyObject
169
- include ObjectInspector::InspectorsHelper
170
-
171
- private
172
-
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"
178
- end
179
-
180
- MyObject.new.inspect
181
- # => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
182
- ```
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.
115
+ Instead of including `ObjectInspector::InspectBehaviors` directly, it may be useful to define your own mix-in.
187
116
 
188
117
  ```ruby
189
118
  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
119
+ include ObjectInspector::InspectBehaviors
196
120
 
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.
121
+ # For defining #inspect chains.
202
122
  def introspect
123
+ # { self => ... }
203
124
  self
204
125
  end
205
126
  end
@@ -207,31 +128,39 @@ end
207
128
 
208
129
  ## Scopes
209
130
 
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.
211
- The default value is `ObjectInspector::Scope.new(:self)`.
131
+ Use the `scope` option to define when each of the `inspect_*` methods should be included. The default scope is `:self`, or `ObjectInspector::Scope.new(:self)`.
212
132
 
213
133
  ### Scope Names
214
134
 
215
- ObjectInspector::Scope acts like [ActiveSupport::StringInquirer](http://api.rubyonrails.org/classes/ActiveSupport/StringInquirer.html). This is a prettier way to test for a given type of "scope" within objects.
135
+ ObjectInspector::Scope acts like an [ActiveSupport::StringInquirer](http://api.rubyonrails.org/classes/ActiveSupport/StringInquirer.html).
216
136
 
217
- The ObjectInspector::Scope objects in these examples are the same as specifying `<scope_name>` like this:
137
+ Call `inspect` with a scope name like:
218
138
 
219
139
  ```ruby
220
140
  my_object.inspect(scope: <scope_name>)
221
141
  ```
222
142
 
223
- Options:
143
+ #### Default Scope Names:
144
+
145
+ The default scope is: `:self`.
146
+
147
+ - `:self` (Default): Is meant to restrict object interrogation to self.
224
148
 
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.
149
+ #### Custom Scope Names:
150
+
151
+ Beyond just `:self`, any name can be used to define any scope that makes sense for your project. No need to provision them up front, just start using them! Suggested additional scope names include:
152
+
153
+ - `:verbose`: For extra detail that may not normally be needed.
154
+ - `:complex`: For revealing collaborating objects (used to prevent n+1 queries in the normal case)
228
155
 
229
156
  ```ruby
230
- scope = ObjectInspector::Scope.new
231
- scope.self? # => true
232
- scope.verbose? # => false
233
- scope.complex? # => false
234
- scope.<anything>? # => false
157
+ def inspect(scope:)
158
+ scope.inspect # => <ObjectInspector::Scope :: ["self"]>
159
+ scope.self? # => true
160
+ scope.verbose? # => false
161
+ scope.complex? # => false
162
+ scope.<anything>? # => false
163
+ end
235
164
  ```
236
165
 
237
166
  #### Multiple Scope Names
@@ -239,10 +168,12 @@ scope.<anything>? # => false
239
168
  It is also possible to pass in multiple scope names to match on.
240
169
 
241
170
  ```ruby
242
- scope = ObjectInspector::Scope.new(%i[verbose complex])
243
- scope.self? # => false
244
- scope.verbose? # => true
245
- scope.complex? # => true
171
+ def inspect(scope: %i[verbose complex])
172
+ scope.inspect # => <ObjectInspector::Scope :: ["complex", "verbose"]>
173
+ scope.self? # => false
174
+ scope.verbose? # => true
175
+ scope.complex? # => true
176
+ end
246
177
  ```
247
178
 
248
179
  #### The "Wild Card" Scope
@@ -250,14 +181,16 @@ scope.complex? # => true
250
181
  Finally, `:all` is a "wild card" scope name, and will match on all scope names.
251
182
 
252
183
  ```ruby
253
- scope = ObjectInspector::Scope.new(:all)
254
- scope.self? # => true
255
- scope.verbose? # => true
256
- scope.complex? # => true
257
- scope.all? # => true
184
+ def inspect(scope: :all)
185
+ scope.inspect # => <ObjectInspector::Scope :: ["all"]>
186
+ scope.self? # => true
187
+ scope.verbose? # => true
188
+ scope.complex? # => true
189
+ scope.all? # => true
190
+ end
258
191
  ```
259
192
 
260
- _**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectorsHelper` is equivalent to passing in the "wild card" scope.
193
+ _**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectBehaviors` is equivalent to passing in the "wild card" scope.
261
194
 
262
195
  ### Scope blocks
263
196
 
@@ -265,8 +198,8 @@ Passing a block to a scope predicate falls back to the out-of-scope placeholder
265
198
 
266
199
  ```ruby
267
200
  scope = ObjectInspector::Scope.new(:verbose)
268
- scope.verbose? { "MATCH" } # => "MATCH"
269
- scope.complex? { "MATCH" } # => "*"
201
+ scope.verbose? { "MATCH" } # => "MATCH"
202
+ scope.complex? { "MATCH" } # => "*"
270
203
  ```
271
204
 
272
205
  ### Scope Joiners
@@ -274,10 +207,10 @@ scope.complex? { "MATCH" } # => "*"
274
207
  ObjectInspector::Scope also offers helper methods for uniformly joining inspect elements:
275
208
 
276
209
  ```ruby
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
210
+ scope.join_name # Joins name parts with ` - ` by default
211
+ scope.join_flags # Joins flags with ` / ` by default
212
+ scope.join_issues # Joins issues with ` | ` by default
213
+ scope.join_info # Joins info items with ` | ` by default
281
214
  ```
282
215
 
283
216
  For example:
@@ -294,7 +227,7 @@ scope.join_info([1, 2, 3, nil]) # => "1 | 2 | 3"
294
227
 
295
228
  ```ruby
296
229
  class MyObject
297
- include ObjectInspector::InspectorsHelper
230
+ include ObjectInspector::InspectBehaviors
298
231
 
299
232
  attr_reader :name,
300
233
  :a2
@@ -320,7 +253,8 @@ class MyObject
320
253
  private
321
254
 
322
255
  def inspect_identification
323
- identify(:a2)
256
+ # Or use `identify(:a2)` from the Object Identifier gem (see Supporting Gems).
257
+ "#{self.class.name}[#{a2}]"
324
258
  end
325
259
 
326
260
  def inspect_flags(scope:)
@@ -377,16 +311,16 @@ my_object.inspect! # 👀 Same as passing in `scope: :all`
377
311
  # => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
378
312
 
379
313
  ObjectInspector.configuration.default_scope = :complex
380
- my_object.inspect
381
- # => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>"
314
+ my_object # =>
315
+ <MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>
382
316
 
383
317
  ObjectInspector.configuration.default_scope = %i[self complex verbose]
384
- my_object.inspect
385
- # => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
318
+ my_object # =>
319
+ <MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>
386
320
 
387
321
  ObjectInspector.configuration.default_scope = :all
388
- my_object.inspect
389
- # => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
322
+ my_object # =>
323
+ <MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>
390
324
  ```
391
325
 
392
326
  ## Wrapped Objects
@@ -395,7 +329,7 @@ If the Object being inspected wraps another object--i.e. defines #to_model and #
395
329
 
396
330
  ```ruby
397
331
  class MyWrapperObject
398
- include ObjectInspector::InspectorsHelper
332
+ include ObjectInspector::InspectBehaviors
399
333
 
400
334
  def to_model
401
335
  @to_model ||= MyWrappedObject.new
@@ -408,7 +342,7 @@ class MyWrapperObject
408
342
  end
409
343
 
410
344
  class MyWrappedObject
411
- include ObjectInspector::InspectorsHelper
345
+ include ObjectInspector::InspectBehaviors
412
346
 
413
347
  private
414
348
 
@@ -417,11 +351,11 @@ class MyWrappedObject
417
351
  def inspect_issues(scope:) = scope.complex? { "CI1" }
418
352
  end
419
353
 
420
- MyWrapperObject.new.inspect
421
- # => "<MyWrapperObject(WRAPPER_FLAG1) !!*!!> <MyWrappedObject(FLAG1 / FLAG2) !!*!! INFO>"
354
+ MyWrapperObject.new # =>
355
+ <MyWrapperObject(WRAPPER_FLAG1) !!*!!> <MyWrappedObject(FLAG1 / FLAG2) !!*!! INFO>
422
356
 
423
- MyWrapperObject.new.inspect!
424
- # => "<MyWrapperObject(WRAPPER_FLAG1) !!CI1!!> <MyWrappedObject(FLAG1 / FLAG2) !!CI1!! INFO>"
357
+ MyWrapperObject.new.inspect! # =>
358
+ <MyWrapperObject(WRAPPER_FLAG1) !!CI1!!> <MyWrappedObject(FLAG1 / FLAG2) !!CI1!! INFO>
425
359
  ```
426
360
 
427
361
  This feature is recursive.
@@ -432,7 +366,7 @@ If the Object being inspected is wrapped by an object that delegates all unknown
432
366
 
433
367
  ```ruby
434
368
  class MyDelegatingWrapperObject
435
- include ObjectInspector::InspectorsHelper
369
+ include ObjectInspector::InspectBehaviors
436
370
 
437
371
  def initialize(my_object)
438
372
  @my_object = my_object
@@ -463,7 +397,7 @@ class MyDelegatingWrapperObject
463
397
  end
464
398
 
465
399
  class MyWrappedObject
466
- include ObjectInspector::InspectorsHelper
400
+ include ObjectInspector::InspectBehaviors
467
401
 
468
402
  def display_name
469
403
  "WRAPPED_OBJECT_NAME"
@@ -477,8 +411,8 @@ class MyWrappedObject
477
411
  def inspect_name = "NAME"
478
412
  end
479
413
 
480
- MyDelegatingWrapperObject.new(MyWrappedObject.new).inspect
481
- # => "<MyDelegatingWrapperObject> <MyWrappedObject(FLAG1) !!ISSUE1!! INFO :: NAME>"
414
+ MyDelegatingWrapperObject.new(MyWrappedObject.new) # =>
415
+ <MyDelegatingWrapperObject> <MyWrappedObject(FLAG1) !!ISSUE1!! INFO :: NAME>
482
416
  ```
483
417
 
484
418
  ## On-the-fly Inspect Methods
@@ -487,7 +421,7 @@ When passed as an option (as opposed to being called via an Object-defined metho
487
421
 
488
422
  ```ruby
489
423
  class MyObject
490
- include ObjectInspector::InspectorsHelper
424
+ include ObjectInspector::InspectBehaviors
491
425
 
492
426
  def my_method1 = "Result1"
493
427
  def my_method2 = "Result2"
@@ -495,9 +429,9 @@ class MyObject
495
429
  def inspect_info = :my_method2
496
430
  end
497
431
 
498
- MyObject.new.inspect(info: "my_method1") # => "<MyObject my_method1>"
499
- MyObject.new.inspect(info: :my_method2) # => "<MyObject Result2>"
500
- MyObject.new.inspect # => "<MyObject my_method2>"
432
+ MyObject.new.inspect(info: "my_method1") # => "<MyObject my_method1>"
433
+ MyObject.new.inspect(info: :my_method2) # => "<MyObject Result2>"
434
+ MyObject.new.inspect # => "<MyObject my_method2>"
501
435
  ```
502
436
 
503
437
  ## Clearing Output for Specified Inspect Method
@@ -506,7 +440,7 @@ Pass `nil` to any inspect method type to not display it:
506
440
 
507
441
  ```ruby
508
442
  class MyObject
509
- include ObjectInspector::InspectorsHelper
443
+ include ObjectInspector::InspectBehaviors
510
444
 
511
445
  def inspect_identification = "My Object"
512
446
  def inspect_info = "INFO"
@@ -523,6 +457,38 @@ MyObject.new.inspect(identification: nil, info: nil, flags: nil, issues: nil, na
523
457
  # => "<MyObject>"
524
458
  ```
525
459
 
460
+ ## Temporarily Disabling ObjectInspector
461
+
462
+ To disable / re-enable Object Inspector output for the current session:
463
+
464
+ ```ruby
465
+ MyObject.new # =>
466
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
467
+
468
+ ObjectInspector.configuration.disable # =>
469
+ -> ObjectInspector disabled
470
+ MyObject.new # =>
471
+ #<MyObject:0x000000012332c458>
472
+
473
+ ObjectInspector.configuration.enable # =>
474
+ -> ObjectInspector enabled
475
+ MyObject.new # =>
476
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
477
+ ```
478
+
479
+ Or, simply toggle the current state:
480
+
481
+ ```ruby
482
+ ObjectInspector.configuration.toggle; # =>
483
+ -> ObjectInspector disabled
484
+
485
+ ObjectInspector.configuration.toggle; # =>
486
+ -> ObjectInspector enabled
487
+ ```
488
+
489
+ _**NOTE**_: `#inspect!` ignores the enabled/disabled setting and still invokes Object
490
+ Inspector -- using the wild-card (`:all`) scope.
491
+
526
492
  ## Custom Formatters
527
493
 
528
494
  A custom inspect formatter can be defined by implementing the interface defined by [ObjectInspector::BaseFormatter](https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/base_formatter.rb). Then, either override the ObjectInspector::Configuration#formatter_class value (see [Configuration](#configuration)) or just pass your custom class name into ObjectInspector::Inspector.new.
@@ -535,7 +501,7 @@ class MyCustomFormatter < ObjectInspector::BaseFormatter
535
501
  end
536
502
 
537
503
  class MyObject
538
- include ObjectInspector::InspectorsHelper
504
+ include ObjectInspector::InspectBehaviors
539
505
 
540
506
  def inspect
541
507
  super(
@@ -547,8 +513,8 @@ class MyObject
547
513
  end
548
514
  end
549
515
 
550
- MyObject.new.inspect
551
- # => "[IDENTIFICATION Flags: FLAG1 / FLAG2 -- Info: INFO -- Name: NAME]"
516
+ MyObject.new # =>
517
+ [IDENTIFICATION Flags: FLAG1 / FLAG2 -- Info: INFO -- Name: NAME]
552
518
  ```
553
519
 
554
520
  See examples:
@@ -556,13 +522,42 @@ See examples:
556
522
  - [ObjectInspector::TemplatingFormatter]
557
523
  - [ObjectInspector::CombiningFormatter]
558
524
 
525
+ ## Help
526
+
527
+ ### How can I see the original inspect output on ActiveRecord objects?
528
+
529
+ Simply [disable Object Inspector](#temporarily-disabling-objectinspector) and you'll see ActiveRecord's Pretty Print formatting shine through again. For example:
530
+
531
+ ```ruby
532
+ class User < ApplicationRecord
533
+ include ObjectInspectionBehaviors # 👀 Defined above.
534
+
535
+ # ...
536
+ end
537
+
538
+ User.new # =>
539
+ <User[1] :: John Smith>
540
+
541
+ ObjectInspector.configuration.disable; # =>
542
+ -> ObjectInspector disabled
543
+
544
+ User.new # =>
545
+ #<User:0x0000000125ce9890
546
+ id: "6c6d6f4b-05fd-4d81-af3e-1947a6a38aa0",
547
+ first_name: "John",
548
+ last_name: "Smith",
549
+ time_zone: nil,
550
+ created_at: "2025-02-10 12:27:23.793833000 -0600",
551
+ updated_at: "2025-02-11 13:15:00.301991000 -0600">
552
+ ```
553
+
559
554
  ## Supporting Gems
560
555
 
561
556
  Object Inspector works great with the [Object Identifier](https://github.com/pdobb/object_identifier) gem.
562
557
 
563
558
  ```ruby
564
559
  class MyObject
565
- include ObjectInspector::InspectorsHelper
560
+ include ObjectInspector::InspectBehaviors
566
561
 
567
562
  def my_method1
568
563
  1
@@ -584,15 +579,92 @@ class MyObject
584
579
  def inspect_name = "NAME"
585
580
  end
586
581
 
587
- MyObject.new.inspect
588
- # => "<MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
582
+ MyObject.new # =>
583
+ <MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
584
+ ```
585
+
586
+ ## Adding Utilities Methods to `.irbrc` / `.pryrc`
587
+
588
+ One may wish to add some convenience methods to their project-local `.irbrc`/`.pryrc` file, and/or their global `~/.irbrc`/`~/.pryrc` file. For example:
589
+
590
+ ```ruby
591
+ # OBJECT INSPECTOR GEM
592
+
593
+ def toggle_object_inspector = ObjectInspector.configuration.toggle
594
+ alias oit toggle_object_inspector
595
+
596
+ def get_object_inspector_current_scope
597
+ ObjectInspector.configuration.default_scope
598
+ end
599
+ alias oi get_object_inspector_current_scope
600
+
601
+ # :self is the gem's default inspection scope.
602
+ def set_object_inspector_scope_self = set_object_inspector_scope(:self)
603
+ alias ois set_object_inspector_scope_self
604
+
605
+ def set_object_inspector_scope_complex = set_object_inspector_scope(:complex)
606
+ alias oic set_object_inspector_scope_complex
607
+
608
+ def set_object_inspector_scope_verbose = set_object_inspector_scope(:verbose)
609
+ alias oiv set_object_inspector_scope_verbose
610
+
611
+ # Set :all (wild-card) inspection scope.
612
+ def set_object_inspector_scope_all = set_object_inspector_scope(:all)
613
+ alias oia set_object_inspector_scope_all
614
+
615
+ # Set a custom scope or set of scopes.
616
+ #
617
+ # @example
618
+ # set_object_inspector_scope(:my_custom_scope)
619
+ # set_object_inspector_scope(:complex, :verbose)
620
+ # set_object_inspector_scope(%i[complex verbose my_custom_scope])
621
+ def set_object_inspector_scope(*names)
622
+ ObjectInspector.configuration.default_scope = *names
623
+ get_object_inspector_current_scope
624
+ end
625
+ alias oiset set_object_inspector_scope
626
+ ```
627
+
628
+ ## Default State
629
+
630
+ > [!IMPORTANT]
631
+ > ObjectInspector defaults to `enabled`. However, this implies an increased chance of causing additional queries/processing based on your usage.
632
+
633
+ If your inspect methods reference other ActiveRecord models, you will be introducing Database queries into basic object inspection. While you can control this through careful use of `complex` scopes (see below), you may wish to default ObjectInspector to be `disabled` across the board for active web / background processes. Then, since ObjectInspector's utility really shines on the the Rails console, you can default it to `enabled` there.
634
+
635
+ To set Object inspector to be `disabled` by default, but `enabled` on the Rails console:
636
+
637
+ 1. In an initializer, set [ObjectInspector::Configuration] to default to `disabled`:
638
+
639
+ ```ruby
640
+ # config/initializers/object_inspector.rb
641
+ ObjectInspector.configure do |config|
642
+ config.enabled = false
643
+ end
644
+ ```
645
+
646
+ 2. Enable ObjectInspector via `.irbrc` (or `.pryrc`, or the like):
647
+
648
+ ```ruby
649
+ # .irbrc:
650
+
651
+ # ...
652
+
653
+ ObjectInspector.configuration.enable
654
+ # Note: ^ produces output: ` -> ObjectInspector enabled`
655
+
656
+ # OR (silent version):
657
+
658
+ ObjectInspector.configure do |config|
659
+ config.enabled = true
660
+ end
589
661
  ```
590
662
 
591
663
  ## Performance
592
664
 
593
665
  ### Benchmarking Object Inspector
594
666
 
595
- ObjectInspetor is ~2.75x slower than Ruby's default inspect, in Ruby v3.4.
667
+ ObjectInspector is ~2.75x slower than Ruby's default inspect, in Ruby v3.4.
596
668
 
597
669
  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.
598
670
 
@@ -679,7 +751,7 @@ To release a new version of this gem to RubyGems:
679
751
 
680
752
  1. Update the version number in `version.rb`
681
753
  2. Update `CHANGELOG.md`
682
- 3. Run `bundle` to update Gemfile.lock with the latest version info
754
+ 3. Run `bundle install` to update Gemfile.lock with the latest version info
683
755
  4. Commit the changes. e.g. `Bump to vX.Y.Z`
684
756
  5. Run `rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
685
757
 
@@ -701,6 +773,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/pdobb/
701
773
 
702
774
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
703
775
 
776
+ [ObjectInspector::Configuration]: https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector.rb
704
777
  [ObjectInspector::TemplatingFormatter]: https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/templating_formatter.rb
705
778
  [ObjectInspector::CombiningFormatter]: https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/combining_formatter.rb
706
779
  [Object Inspector Benchmarking Scripts]: https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/object_inspector.rb
@@ -1,17 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector::Conversions defines conversion functions used by
4
- # ObjectInspector.
3
+ # Defines general conversion functions used by ObjectInspector.
5
4
  module ObjectInspector::Conversions
6
5
  module_function
7
6
 
7
+ # :reek:UncommunicativeMethodName
8
+
8
9
  # Convert the passed in value to an {ObjectInspector::Scope} object.
9
10
  # Just returns the passed in value if it already is an
10
11
  # {ObjectInspector::Scope} object.
11
12
  #
12
- # @return [ObjectInspector::Scope]
13
+ # @example
14
+ # ObjectInspector::Conversions.Scope("test")
15
+ # # => <ObjectInspector::Scope :: ["test"]>
13
16
  #
14
- # :reek:UncommunicativeMethodName
17
+ # ObjectInspector::Conversions.Scope(
18
+ # ObjectInspector::Scope.new(:my_custom_scope),
19
+ # )
20
+ # # => <ObjectInspector::Scope :: ["my_custom_scope"]>
21
+ #
22
+ # @return [ObjectInspector::Scope]
15
23
  def Scope(value) # rubocop:disable Naming/MethodName
16
24
  case value
17
25
  when ObjectInspector::Scope