object_inspector 0.10.0 → 1.0.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: fd42799a69895e8a918436eaa6688090722f4dde5d406f34b36eae201459f82a
4
+ data.tar.gz: 1ea233bec14fddd0b57ffb797da6009471f8f9f989fee45f204af8813b70f59e
5
5
  SHA512:
6
- metadata.gz: 2d02eab73350615584726ada8923bcdea3d428cf61d8e95abf17778b4b76836f828b2c12389dadf1aebe85e369106b4396da1e8501f81fe4e74b44a3031171b8
7
- data.tar.gz: 1d044028f4889d0b6bd5615d5f035e19e5bf6ce7e5a30a30ce54a686edb403dd89a826bf8cfd0c4a89781c862af798d4e50ce9a1ed0080012f33a99ec4e477e1
6
+ metadata.gz: f30121bcdddfd33c7990197e4513eb44a84a487afc4f346a5823067760e2754aaf7ae0871ae58157ef45686de4a885e2db798e97e7a35671c5b0143fedafb11c
7
+ data.tar.gz: 4ed8d2ac33b52b4af28bc621a2e92fd429039c6951a2d8d10a38e866a9d101e2f18d24a60125fb189b367232293068c63a3ca0ec0bdaa1bb6df37119f26db5d0
data/README.md CHANGED
@@ -60,6 +60,7 @@ 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)
@@ -84,7 +85,10 @@ class MyObject
84
85
  end
85
86
  end
86
87
 
87
- MyObject.new.inspect # => "<MyObject>"
88
+ MyObject.new.inspect # => "<MyObject>"
89
+
90
+ MyObject.new # =>
91
+ <MyObject>
88
92
  ```
89
93
 
90
94
  See: [Helper Usage](#helper-usage) for simpler usage.
@@ -106,8 +110,8 @@ class MyObject
106
110
  end
107
111
  end
108
112
 
109
- MyObject.new.inspect
110
- # => "<My Object(FLAG1 / FLAG2) !!ISSUE1!! INFO :: NAME>"
113
+ MyObject.new # =>
114
+ <My Object(FLAG1 / FLAG2) !!ISSUE1!! INFO :: NAME>
111
115
  ```
112
116
 
113
117
  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.
@@ -127,27 +131,28 @@ class MyObject
127
131
  def inspect_name = "NAME" # Or: def display_name = "NAME"
128
132
  end
129
133
 
130
- MyObject.new.inspect
131
- # => "<My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
134
+ MyObject.new # =>
135
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
132
136
  ```
133
137
 
134
138
  ## Helper Usage
135
139
 
136
- To save some typing, include ObjectInspector::InspectHelper into an object and `ObjectInspector::Inspector.inspect` will be called on `self` automatically.
140
+ To save some typing, include ObjectInspector::InspectBehaviors into an object and `ObjectInspector::Inspector.inspect` will be called on `self` automatically.
137
141
 
138
142
  ```ruby
139
143
  class MyObject
140
- include ObjectInspector::InspectorsHelper
144
+ include ObjectInspector::InspectBehaviors
141
145
  end
142
146
 
143
- MyObject.new.inspect # => "<MyObject>"
147
+ MyObject.new # =>
148
+ <MyObject>
144
149
  ```
145
150
 
146
151
  To access the ObjectInspector::Inspector's options via the helper, call into `super`.
147
152
 
148
153
  ```ruby
149
154
  class MyObject
150
- include ObjectInspector::InspectorsHelper
155
+ include ObjectInspector::InspectBehaviors
151
156
 
152
157
  def inspect
153
158
  super(identification: "My Object",
@@ -158,15 +163,15 @@ class MyObject
158
163
  end
159
164
  end
160
165
 
161
- MyObject.new.inspect
162
- # => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
166
+ MyObject.new # =>
167
+ <My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>
163
168
  ```
164
169
 
165
170
  Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) in Object.
166
171
 
167
172
  ```ruby
168
173
  class MyObject
169
- include ObjectInspector::InspectorsHelper
174
+ include ObjectInspector::InspectBehaviors
170
175
 
171
176
  private
172
177
 
@@ -177,34 +182,74 @@ class MyObject
177
182
  def inspect_name = "NAME" # Or: def display_name = "NAME"
178
183
  end
179
184
 
180
- MyObject.new.inspect
181
- # => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
185
+ MyObject.new # =>
186
+ <My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>
182
187
  ```
183
188
 
184
- ### Helper Inclusion
189
+ ### Disabling ObjectInspector
185
190
 
186
- It may be useful to conditionally include ObjectInspector::InspectorsHelper, as well as other similar methods, via a mix-in.
191
+ You may disable / re-enable Object Inspector output (via the included helper method) for the current session:
187
192
 
188
193
  ```ruby
189
- module ObjectInspectionBehaviors
190
- extend ActiveSupport::Concern
194
+ MyObject.new # =>
195
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
191
196
 
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
197
+ ObjectInspector.configuration.disable # =>
198
+ -> ObjectInspector disabled
199
+ MyObject.new # =>
200
+ #<MyObject:0x000000012332c458>
196
201
 
197
- include ObjectInspector::InspectorsHelper
198
- end
202
+ ObjectInspector.configuration.enable # =>
203
+ -> ObjectInspector enabled
204
+ MyObject.new # =>
205
+ <My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
206
+ ```
199
207
 
200
- # An example of another, similar style of method you may wish to utilize in
201
- # this mix-in.
208
+ Or, toggle current state:
209
+
210
+ ```ruby
211
+ ObjectInspector.configuration.toggle; # =>
212
+ -> ObjectInspector disabled
213
+
214
+ ObjectInspector.configuration.toggle; # =>
215
+ -> ObjectInspector enabled
216
+ ```
217
+
218
+ ### Helper Inclusion
219
+
220
+ Instead of including `ObjectInspector::InspectBehaviors` directly, it may be useful to define your own mix-in.
221
+
222
+ ```ruby
223
+ module ObjectInspectionBehaviors
224
+ include ObjectInspector::InspectBehaviors
225
+
226
+ # For defining #inspect chains.
202
227
  def introspect
228
+ # { self => ... }
203
229
  self
204
230
  end
205
231
  end
206
232
  ```
207
233
 
234
+ #### Usage:
235
+
236
+ ```ruby
237
+ class MyObject
238
+ include ObjectInspectionBehaviors # 👀 Defined above.
239
+
240
+ private
241
+
242
+ def inspect_identification = "My Object"
243
+ def inspect_flags = "FLAG1 / FLAG2"
244
+ def inspect_issues = "ISSUE1 | ISSUE2"
245
+ def inspect_info = "INFO"
246
+ def inspect_name = "NAME" # Or: def display_name = "NAME"
247
+ end
248
+
249
+ MyObject.new # =>
250
+ <My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>
251
+ ```
252
+
208
253
  ## Scopes
209
254
 
210
255
  Use the `scope` option to define the scope of the `inspect_*` methods. The supplied value will be wrapped by the ObjectInspector::Scope helper object.
@@ -212,7 +257,7 @@ The default value is `ObjectInspector::Scope.new(:self)`.
212
257
 
213
258
  ### Scope Names
214
259
 
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.
260
+ ObjectInspector::Scope acts like an [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.
216
261
 
217
262
  The ObjectInspector::Scope objects in these examples are the same as specifying `<scope_name>` like this:
218
263
 
@@ -240,9 +285,9 @@ It is also possible to pass in multiple scope names to match on.
240
285
 
241
286
  ```ruby
242
287
  scope = ObjectInspector::Scope.new(%i[verbose complex])
243
- scope.self? # => false
244
- scope.verbose? # => true
245
- scope.complex? # => true
288
+ scope.self? # => false
289
+ scope.verbose? # => true
290
+ scope.complex? # => true
246
291
  ```
247
292
 
248
293
  #### The "Wild Card" Scope
@@ -251,13 +296,13 @@ Finally, `:all` is a "wild card" scope name, and will match on all scope names.
251
296
 
252
297
  ```ruby
253
298
  scope = ObjectInspector::Scope.new(:all)
254
- scope.self? # => true
255
- scope.verbose? # => true
256
- scope.complex? # => true
257
- scope.all? # => true
299
+ scope.self? # => true
300
+ scope.verbose? # => true
301
+ scope.complex? # => true
302
+ scope.all? # => true
258
303
  ```
259
304
 
260
- _**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectorsHelper` is equivalent to passing in the "wild card" scope.
305
+ _**NOTE**_: Calling `#inspect!` on an object that mixes in `ObjectInspector::InspectBehaviors` is equivalent to passing in the "wild card" scope.
261
306
 
262
307
  ### Scope blocks
263
308
 
@@ -265,8 +310,8 @@ Passing a block to a scope predicate falls back to the out-of-scope placeholder
265
310
 
266
311
  ```ruby
267
312
  scope = ObjectInspector::Scope.new(:verbose)
268
- scope.verbose? { "MATCH" } # => "MATCH"
269
- scope.complex? { "MATCH" } # => "*"
313
+ scope.verbose? { "MATCH" } # => "MATCH"
314
+ scope.complex? { "MATCH" } # => "*"
270
315
  ```
271
316
 
272
317
  ### Scope Joiners
@@ -274,10 +319,10 @@ scope.complex? { "MATCH" } # => "*"
274
319
  ObjectInspector::Scope also offers helper methods for uniformly joining inspect elements:
275
320
 
276
321
  ```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
322
+ scope.join_name # Joins name parts with ` - ` by default
323
+ scope.join_flags # Joins flags with ` / ` by default
324
+ scope.join_issues # Joins issues with ` | ` by default
325
+ scope.join_info # Joins info items with ` | ` by default
281
326
  ```
282
327
 
283
328
  For example:
@@ -294,7 +339,7 @@ scope.join_info([1, 2, 3, nil]) # => "1 | 2 | 3"
294
339
 
295
340
  ```ruby
296
341
  class MyObject
297
- include ObjectInspector::InspectorsHelper
342
+ include ObjectInspector::InspectBehaviors
298
343
 
299
344
  attr_reader :name,
300
345
  :a2
@@ -377,16 +422,16 @@ my_object.inspect! # 👀 Same as passing in `scope: :all`
377
422
  # => "<MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>"
378
423
 
379
424
  ObjectInspector.configuration.default_scope = :complex
380
- my_object.inspect
381
- # => "<MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>"
425
+ my_object # =>
426
+ <MyObject[2](DEFAULT_FLAG / *) !!I1 | *!! Default Info | Complex Info | * :: Name>
382
427
 
383
428
  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>"
429
+ my_object # =>
430
+ <MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>
386
431
 
387
432
  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>"
433
+ my_object # =>
434
+ <MyObject[2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!I1 | VI2!! Default Info | Complex Info | Verbose Info :: Name>
390
435
  ```
391
436
 
392
437
  ## Wrapped Objects
@@ -395,7 +440,7 @@ If the Object being inspected wraps another object--i.e. defines #to_model and #
395
440
 
396
441
  ```ruby
397
442
  class MyWrapperObject
398
- include ObjectInspector::InspectorsHelper
443
+ include ObjectInspector::InspectBehaviors
399
444
 
400
445
  def to_model
401
446
  @to_model ||= MyWrappedObject.new
@@ -408,7 +453,7 @@ class MyWrapperObject
408
453
  end
409
454
 
410
455
  class MyWrappedObject
411
- include ObjectInspector::InspectorsHelper
456
+ include ObjectInspector::InspectBehaviors
412
457
 
413
458
  private
414
459
 
@@ -417,11 +462,11 @@ class MyWrappedObject
417
462
  def inspect_issues(scope:) = scope.complex? { "CI1" }
418
463
  end
419
464
 
420
- MyWrapperObject.new.inspect
421
- # => "<MyWrapperObject(WRAPPER_FLAG1) !!*!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!*!! INFO>"
465
+ MyWrapperObject.new # =>
466
+ <MyWrapperObject(WRAPPER_FLAG1) !!*!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!*!! INFO>
422
467
 
423
- MyWrapperObject.new.inspect!
424
- # => "<MyWrapperObject(WRAPPER_FLAG1) !!CI1!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!CI1!! INFO>"
468
+ MyWrapperObject.new! # =>
469
+ <MyWrapperObject(WRAPPER_FLAG1) !!CI1!!> ⇨ <MyWrappedObject(FLAG1 / FLAG2) !!CI1!! INFO>
425
470
  ```
426
471
 
427
472
  This feature is recursive.
@@ -432,7 +477,7 @@ If the Object being inspected is wrapped by an object that delegates all unknown
432
477
 
433
478
  ```ruby
434
479
  class MyDelegatingWrapperObject
435
- include ObjectInspector::InspectorsHelper
480
+ include ObjectInspector::InspectBehaviors
436
481
 
437
482
  def initialize(my_object)
438
483
  @my_object = my_object
@@ -463,7 +508,7 @@ class MyDelegatingWrapperObject
463
508
  end
464
509
 
465
510
  class MyWrappedObject
466
- include ObjectInspector::InspectorsHelper
511
+ include ObjectInspector::InspectBehaviors
467
512
 
468
513
  def display_name
469
514
  "WRAPPED_OBJECT_NAME"
@@ -477,8 +522,8 @@ class MyWrappedObject
477
522
  def inspect_name = "NAME"
478
523
  end
479
524
 
480
- MyDelegatingWrapperObject.new(MyWrappedObject.new).inspect
481
- # => "<MyDelegatingWrapperObject> ⇨ <MyWrappedObject(FLAG1) !!ISSUE1!! INFO :: NAME>"
525
+ MyDelegatingWrapperObject.new(MyWrappedObject.new) # =>
526
+ <MyDelegatingWrapperObject> ⇨ <MyWrappedObject(FLAG1) !!ISSUE1!! INFO :: NAME>
482
527
  ```
483
528
 
484
529
  ## On-the-fly Inspect Methods
@@ -487,7 +532,7 @@ When passed as an option (as opposed to being called via an Object-defined metho
487
532
 
488
533
  ```ruby
489
534
  class MyObject
490
- include ObjectInspector::InspectorsHelper
535
+ include ObjectInspector::InspectBehaviors
491
536
 
492
537
  def my_method1 = "Result1"
493
538
  def my_method2 = "Result2"
@@ -495,9 +540,9 @@ class MyObject
495
540
  def inspect_info = :my_method2
496
541
  end
497
542
 
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>"
543
+ MyObject.new.inspect(info: "my_method1") # => "<MyObject my_method1>"
544
+ MyObject.new.inspect(info: :my_method2) # => "<MyObject Result2>"
545
+ MyObject.new.inspect # => "<MyObject my_method2>"
501
546
  ```
502
547
 
503
548
  ## Clearing Output for Specified Inspect Method
@@ -506,7 +551,7 @@ Pass `nil` to any inspect method type to not display it:
506
551
 
507
552
  ```ruby
508
553
  class MyObject
509
- include ObjectInspector::InspectorsHelper
554
+ include ObjectInspector::InspectBehaviors
510
555
 
511
556
  def inspect_identification = "My Object"
512
557
  def inspect_info = "INFO"
@@ -535,7 +580,7 @@ class MyCustomFormatter < ObjectInspector::BaseFormatter
535
580
  end
536
581
 
537
582
  class MyObject
538
- include ObjectInspector::InspectorsHelper
583
+ include ObjectInspector::InspectBehaviors
539
584
 
540
585
  def inspect
541
586
  super(
@@ -547,8 +592,8 @@ class MyObject
547
592
  end
548
593
  end
549
594
 
550
- MyObject.new.inspect
551
- # => "[IDENTIFICATION Flags: FLAG1 / FLAG2 -- Info: INFO -- Name: NAME]"
595
+ MyObject.new # =>
596
+ [IDENTIFICATION Flags: FLAG1 / FLAG2 -- Info: INFO -- Name: NAME]
552
597
  ```
553
598
 
554
599
  See examples:
@@ -556,13 +601,42 @@ See examples:
556
601
  - [ObjectInspector::TemplatingFormatter]
557
602
  - [ObjectInspector::CombiningFormatter]
558
603
 
604
+ ## Help
605
+
606
+ ### How can I see the original inspect output on ActiveRecord objects?
607
+
608
+ Simply [disable Object Inspector](#disabling-object-inspector) and you'll see ActiveRecord's Pretty Print formatting shine through again. For example:
609
+
610
+ ```ruby
611
+ class User < ApplicationRecord
612
+ include ObjectInspectionBehaviors # 👀 Defined above.
613
+
614
+ # ...
615
+ end
616
+
617
+ User.new # =>
618
+ <User[1] :: John Smith>
619
+
620
+ ObjectInspector.configuration.disable; # =>
621
+ -> ObjectInspector disabled
622
+
623
+ User.new # =>
624
+ #<User:0x0000000125ce9890
625
+ id: "6c6d6f4b-05fd-4d81-af3e-1947a6a38aa0",
626
+ first_name: "John",
627
+ last_name: "Smith",
628
+ time_zone: nil,
629
+ created_at: "2025-02-10 12:27:23.793833000 -0600",
630
+ updated_at: "2025-02-11 13:15:00.301991000 -0600">
631
+ ```
632
+
559
633
  ## Supporting Gems
560
634
 
561
635
  Object Inspector works great with the [Object Identifier](https://github.com/pdobb/object_identifier) gem.
562
636
 
563
637
  ```ruby
564
638
  class MyObject
565
- include ObjectInspector::InspectorsHelper
639
+ include ObjectInspector::InspectBehaviors
566
640
 
567
641
  def my_method1
568
642
  1
@@ -584,8 +658,50 @@ class MyObject
584
658
  def inspect_name = "NAME"
585
659
  end
586
660
 
587
- MyObject.new.inspect
588
- # => "<MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
661
+ MyObject.new # =>
662
+ <MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>
663
+ ```
664
+
665
+ ## Adding Utilities Methods to `.irbrc` / `.pryrc`
666
+
667
+ One may wish to add some convenience methods to their project-local `.irbrc`/`.pryrc` file, and/or their global `~/.irbrc`/`~/.pryrc` file. For example:
668
+
669
+ ```ruby
670
+ # OBJECT INSPECTOR GEM
671
+
672
+ def toggle_object_inspector = ObjectInspector.configuration.toggle
673
+ alias oit toggle_object_inspector
674
+
675
+ def get_object_inspector_current_scope
676
+ ObjectInspector.configuration.default_scope
677
+ end
678
+ alias oi get_object_inspector_current_scope
679
+
680
+ # :simple is the default inspection scope.
681
+ def set_object_inspector_scope_simple = set_object_inspector_scope(:simple)
682
+ alias ois set_object_inspector_scope_simple
683
+
684
+ def set_object_inspector_scope_complex = set_object_inspector_scope(:complex)
685
+ alias oic set_object_inspector_scope_complex
686
+
687
+ def set_object_inspector_scope_verbose = set_object_inspector_scope(:verbose)
688
+ alias oiv set_object_inspector_scope_verbose
689
+
690
+ # Set :all (wild-card) inspection scope.
691
+ def set_object_inspector_scope_all = set_object_inspector_scope(:all)
692
+ alias oia set_object_inspector_scope_all
693
+
694
+ # Set a custom scope or set of scopes.
695
+ #
696
+ # @example
697
+ # set_object_inspector_scope(:my_custom_scope)
698
+ # set_object_inspector_scope(:complex, :verbose)
699
+ # set_object_inspector_scope(%i[complex verbose my_custom_scope])
700
+ def set_object_inspector_scope(*names)
701
+ ObjectInspector.configuration.default_scope = *names
702
+ get_object_inspector_current_scope
703
+ end
704
+ alias oiset set_object_inspector_scope
589
705
  ```
590
706
 
591
707
  ## Performance
@@ -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
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector::BaseFormatter is an abstract base class that interfaces
4
- # with {ObjectInspector::Inspector} objects to combine the supplied
5
- # {#identification}, {#flags}, {#info}, and {#name} strings into a friendly
6
- # "inspect" String.
3
+ # An abstract base class that interfaces with {ObjectInspector::Inspector}
4
+ # objects to combine the supplied {#identification}, {#flags}, {#info}, and
5
+ # {#name} strings into a friendly "inspect" String.
7
6
  class ObjectInspector::BaseFormatter
8
7
  attr_reader :inspector
9
8
 
@@ -21,49 +20,49 @@ class ObjectInspector::BaseFormatter
21
20
 
22
21
  # Delegates to {Inspector#wrapped_object_inspection_result}.
23
22
  #
24
- # @return [String] if given
25
- # @return [NilClass] if not given
23
+ # @return [String] If given.
24
+ # @return [NilClass] If not given.
26
25
  def wrapped_object_inspection_result
27
26
  @wrapped_object_inspection_result ||=
28
- @inspector.wrapped_object_inspection_result
27
+ inspector.wrapped_object_inspection_result
29
28
  end
30
29
 
31
30
  # Delegates to {Inspector#identification}.
32
31
  #
33
- # @return [String] if given
32
+ # @return [String] If given.
34
33
  def identification
35
- @identification ||= @inspector.identification
34
+ @identification ||= inspector.identification
36
35
  end
37
36
 
38
37
  # Delegates to {Inspector#flags}.
39
38
  #
40
- # @return [String] if given
41
- # @return [NilClass] if not given
39
+ # @return [String] If given.
40
+ # @return [NilClass] If not given.
42
41
  def flags
43
- @flags ||= @inspector.flags
42
+ @flags ||= inspector.flags
44
43
  end
45
44
 
46
45
  # Delegates to {Inspector#issues}.
47
46
  #
48
- # @return [String] if given
49
- # @return [NilClass] if not given
47
+ # @return [String] If given.
48
+ # @return [NilClass] If not given.
50
49
  def issues
51
- @issues ||= @inspector.issues
50
+ @issues ||= inspector.issues
52
51
  end
53
52
 
54
53
  # Delegates to {Inspector#info}.
55
54
  #
56
- # @return [String] if given
57
- # @return [NilClass] if not given
55
+ # @return [String] If given.
56
+ # @return [NilClass] If not given.
58
57
  def info
59
- @info ||= @inspector.info
58
+ @info ||= inspector.info
60
59
  end
61
60
 
62
61
  # Delegates to {Inspector#name}.
63
62
  #
64
- # @return [String] if given
65
- # @return [NilClass] if not given
63
+ # @return [String] If given.
64
+ # @return [NilClass] If not given.
66
65
  def name
67
- @name ||= @inspector.name
66
+ @name ||= inspector.name
68
67
  end
69
68
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector::CombiningFormatter implements
4
- # {ObjectInspector::BaseFormatter} to return the standard/default inspect
5
- # output format by combining Strings.
3
+ # Specializes on {ObjectInspector::BaseFormatter} to return the standard/default
4
+ # inspect output format by combining Strings.
6
5
  #
7
6
  # @attr (see BaseFormatter)
8
7
  class ObjectInspector::CombiningFormatter < ObjectInspector::BaseFormatter
@@ -4,9 +4,8 @@
4
4
  # :reek:TooManyMethods
5
5
  # rubocop:disable Metrics/ClassLength
6
6
 
7
- # ObjectInspector::TemplatingFormatter specializes on
8
- # {ObjectInspector::BaseFormatter} to return the standard/default inspect
9
- # output format via String templates.
7
+ # Specializes on {ObjectInspector::BaseFormatter} to return the standard/default
8
+ # inspect output format using String templates.
10
9
  #
11
10
  # @attr (see BaseFormatter)
12
11
  class ObjectInspector::TemplatingFormatter < ObjectInspector::BaseFormatter
@@ -52,8 +51,7 @@ class ObjectInspector::TemplatingFormatter < ObjectInspector::BaseFormatter
52
51
  "#{wrapped_object_inspection_result}"
53
52
  end
54
53
 
55
- # rubocop:disable Metrics/MethodLength
56
- def build_string
54
+ def build_string # rubocop:disable Metrics/MethodLength
57
55
  if flags
58
56
  build_string_with_flags_and_maybe_issues_and_info_and_name
59
57
  elsif issues
@@ -66,7 +64,6 @@ class ObjectInspector::TemplatingFormatter < ObjectInspector::BaseFormatter
66
64
  build_base_string
67
65
  end
68
66
  end
69
- # rubocop:enable Metrics/MethodLength
70
67
 
71
68
  def build_string_with_flags_and_maybe_issues_and_info_and_name
72
69
  if issues
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ObjectInspector::InspectBehaviors can be included into any object to override
4
+ # the default `#inspect` method for that object to instead call
5
+ # {ObjectInspector::Inspector.inspect}.
6
+ module ObjectInspector::InspectBehaviors
7
+ # Calls {ObjectInspector::Inspector.inspect} on the passed in `object`,
8
+ # passing through any keyword arguments.
9
+ #
10
+ # @return [String]
11
+ def inspect(**)
12
+ return super() if ObjectInspector.configuration.disabled?
13
+
14
+ ObjectInspector::Inspector.inspect(self, **)
15
+ end
16
+
17
+ # Like {#inspect} but forces scope to `:all`. This (the bang (!) version) is
18
+ # considered the "more dangerous" version of {#inspect} in the sense that the
19
+ # `:all` scope may result in additional queries or extra processing--depending
20
+ # on how the inspect hooks are setup.
21
+ #
22
+ # @return [String]
23
+ def inspect!(**)
24
+ ObjectInspector::Inspector.inspect(self, **, scope: :all)
25
+ end
26
+
27
+ private
28
+
29
+ # :reek:UtilityFunction
30
+
31
+ # Allow ActiveRecord::Core#pretty_print to produce the standard Pretty-printed
32
+ # output (vs just straight #inspect String) when ObjectInspector is disabled.
33
+ def custom_inspect_method_defined?
34
+ ObjectInspector.configuration.enabled?
35
+ end
36
+ end
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector::Inspector organizes inspection of the associated {#object}
4
- # via the passed in options and via an {ObjectInspector::BaseFormatter}
5
- # instance.
6
- #
7
3
  # :reek:TooManyMethods
4
+
5
+ # Organizes inspection of the associated {#object} via the passed in options and
6
+ # via an {ObjectInspector::BaseFormatter} instance.
7
+ #
8
+ # @example
9
+ # ObjectInspector::Inspector.inspect(
10
+ # self,
11
+ # identification: self.class.name,
12
+ # flags: "FLAG1",
13
+ # issues: "ISSUE1",
14
+ # info: "INFO",
15
+ # name: "NAME",
16
+ # )
17
+ # # => "<Object(FLAG1) !!ISSUE1!! INFO :: NAME>"
8
18
  class ObjectInspector::Inspector
9
19
  attr_reader :object
10
20
 
@@ -12,9 +22,9 @@ class ObjectInspector::Inspector
12
22
  # required to use ObjectInspector::Inspector.
13
23
  #
14
24
  # @return [String]
15
- def self.inspect(...)
16
- new(...).to_s
17
- end
25
+ def self.inspect(...) = new(...).to_s
26
+
27
+ # :reek:DuplicateMethodCall (ObjectInspecto.configuration)
18
28
 
19
29
  # @param object [Object] the object being inspected
20
30
  # @param scope [Symbol] Object inspection type. For example:
@@ -22,18 +32,17 @@ class ObjectInspector::Inspector
22
32
  # <custom> -- Anything else that makes sense for {#object} to key
23
33
  # on
24
34
  # @param formatter [ObjectInspector::BaseFormatter]
25
- # (ObjectInspector.configuration.formatter) the formatter object type
26
- # to use for formatting the inspect String
27
- # @param kwargs [Hash] options to be sent to {#object} via the
28
- # {ObjectInspector::ObjectInterrogator} when calling the `inspect_*`
29
- # methods
30
- #
31
- # :reek:DuplicateMethodCall (ObjectInspecto.configuration)
35
+ # (ObjectInspector.configuration.formatter) The formatter object type
36
+ # to use for formatting the inspect String.
37
+ # @param kwargs [Hash] Options to be sent to {#object} via
38
+ # {ObjectInspector::InterrogateObject} when calling the `inspect_*`
39
+ # methods.
32
40
  def initialize(
33
- object,
34
- scope: ObjectInspector.configuration.default_scope,
35
- formatter: ObjectInspector.configuration.formatter_class,
36
- **kwargs)
41
+ object,
42
+ scope: ObjectInspector.configuration.default_scope,
43
+ formatter: ObjectInspector.configuration.formatter_class,
44
+ **kwargs
45
+ )
37
46
  @object = object
38
47
  @scope = ObjectInspector::Conversions.Scope(scope)
39
48
  @formatter_class = formatter
@@ -50,8 +59,8 @@ class ObjectInspector::Inspector
50
59
  # Generate the inspect String for the wrapped object, if `self` is a wrapper
51
60
  # object.
52
61
  #
53
- # @return [String] if {#object_is_a_wrapper?}
54
- # @return [NilClass] if not {#object_is_a_wrapper?}
62
+ # @return [String] If {#object_is_a_wrapper?}.
63
+ # @return [NilClass] If not {#object_is_a_wrapper?}.
55
64
  def wrapped_object_inspection_result
56
65
  return unless object_is_a_wrapper?
57
66
 
@@ -59,7 +68,8 @@ class ObjectInspector::Inspector
59
68
  extract_wrapped_object,
60
69
  scope: @scope,
61
70
  formatter: @formatter_class,
62
- kwargs: @kwargs)
71
+ kwargs: @kwargs,
72
+ )
63
73
  end
64
74
 
65
75
  # Core object identification details, such as the {#object} class name and
@@ -67,62 +77,68 @@ class ObjectInspector::Inspector
67
77
  #
68
78
  # @return [String]
69
79
  def identification
70
- (value(key: :identification) || @object.class).to_s
80
+ (value(key: :identification) || object.class).to_s
71
81
  end
72
82
 
73
83
  # Boolean flags/states applicable to {#object}.
74
84
  #
75
- # @return [String] if given
76
- # @return [NilClass] if not given
85
+ # @return [String] If given.
86
+ # @return [NilClass] If not given.
77
87
  def flags
78
88
  value(key: :flags)
79
89
  end
80
90
 
81
91
  # Issues/Warnings applicable to {#object}.
82
92
  #
83
- # @return [String] if given
84
- # @return [NilClass] if not given
93
+ # @return [String] If given.
94
+ # @return [NilClass] If not given.
85
95
  def issues
86
96
  value(key: :issues)
87
97
  end
88
98
 
89
99
  # Informational details applicable to {#object}.
90
100
  #
91
- # @return [String] if given
92
- # @return [NilClass] if not given
101
+ # @return [String] If given.
102
+ # @return [NilClass] If not given.
93
103
  def info
94
104
  value(key: :info)
95
105
  end
96
106
 
97
107
  # A human-friendly identifier for {#object}.
98
108
  #
99
- # @return [String] if given
100
- # @return [NilClass] if not given
109
+ # @return [String] If given.
110
+ # @return [NilClass] If not given.
101
111
  def name
102
112
  key = :name
103
113
 
104
114
  if @kwargs.key?(key)
105
- value(key: key)
115
+ value(key:)
106
116
  else
107
117
  interrogate_object_inspect_method(key) ||
108
118
  interrogate_object(
109
- method_name: :display_name, kwargs: object_method_keyword_arguments)
119
+ method_name: :display_name,
120
+ kwargs: object_method_keyword_arguments,
121
+ )
110
122
  end
111
123
  end
112
124
 
113
125
  private
114
126
 
127
+ attr_reader :scope,
128
+ :formatter_class,
129
+ :kwargs
130
+
115
131
  def formatter
116
- @formatter_class.new(self)
132
+ formatter_class.new(self)
117
133
  end
118
134
 
119
- # @return [String] if `key` is found in {#kwargs} or if {#object} responds to
120
- # `#{object_inspection_method_name}` (e.g. `inspect_flags`)
121
- # @return [NilClass] if not found in {#kwargs} or {#object}
135
+ # @return [String] If `key` is found in {#kwargs} or if {#object} responds to
136
+ # `#{object_inspection_method_name}` (e.g. `inspect_flags`).
137
+ # @return [NilClass] If not found in {#kwargs} or {#object}.
122
138
  def value(key:)
123
139
  return_value =
124
- if @kwargs.key?(key)
125
- evaluate_passed_in_value(@kwargs[key])
140
+ if kwargs.key?(key)
141
+ evaluate_passed_in_value(kwargs[key])
126
142
  else
127
143
  interrogate_object_inspect_method(key)
128
144
  end
@@ -133,10 +149,10 @@ class ObjectInspector::Inspector
133
149
  # Call `value` on {#object} if it responds to it and the result is not nil,
134
150
  # else just return `value`.
135
151
  #
136
- # @return [#to_s] if {#object} responds to `value` and if the call result
137
- # isn't nil
138
- # @return [#nil] if {#object} doesn't respond to `value` or if the call
139
- # result is nil
152
+ # @return [#to_s] If {#object} responds to `value` and if the call result
153
+ # isn't nil.
154
+ # @return [#nil] If {#object} doesn't respond to `value` or if the call
155
+ # result is nil.
140
156
  def evaluate_passed_in_value(value)
141
157
  if value.is_a?(Symbol)
142
158
  interrogate_object(method_name: value) || value
@@ -147,47 +163,44 @@ class ObjectInspector::Inspector
147
163
 
148
164
  # Attempt to call `inspect_*` on {#object} based on the passed in `name`.
149
165
  #
150
- # @return [String] if {#object} responds to
151
- # `#{object_inspection_method_name}` (e.g. `inspect_flags`)
152
- # @return [NilClass] if not found on {#object}
166
+ # @return [String] If {#object} responds to
167
+ # `#{object_inspection_method_name}` (e.g. `inspect_flags`).
168
+ # @return [NilClass] If not found on {#object}.
153
169
  def interrogate_object_inspect_method(
154
- name,
155
- prefix: ObjectInspector.configuration.inspect_method_prefix)
170
+ name,
171
+ prefix: ObjectInspector.configuration.inspect_method_prefix
172
+ )
156
173
  interrogate_object(
157
- method_name: object_inspection_method_name(name, prefix: prefix),
158
- kwargs: object_method_keyword_arguments)
174
+ method_name: object_inspection_method_name(name, prefix:),
175
+ kwargs: object_method_keyword_arguments,
176
+ )
159
177
  end
160
178
 
161
179
  def interrogate_object(method_name:, kwargs: {})
162
- interrogator =
163
- ObjectInspector::ObjectInterrogator.new(
164
- object: @object,
165
- method_name: method_name,
166
- kwargs: kwargs)
167
-
168
- interrogator.call
180
+ ObjectInspector::InterrogateObject.(object, method_name:, kwargs:)
169
181
  end
170
182
 
171
183
  # :reek:UtilityFunction
184
+
172
185
  def object_inspection_method_name(
173
- name,
174
- prefix: ObjectInspector.configuration.inspect_method_prefix)
186
+ name,
187
+ prefix: ObjectInspector.configuration.inspect_method_prefix
188
+ )
175
189
  "#{prefix}_#{name}"
176
190
  end
177
191
 
178
192
  def object_method_keyword_arguments
179
- {
180
- scope: @scope,
181
- }
193
+ { scope: }
182
194
  end
183
195
 
184
196
  def extract_wrapped_object
185
- @object.to_model
197
+ object.to_model
186
198
  end
187
199
 
188
200
  # :reek:ManualDispatch
201
+
189
202
  def object_is_a_wrapper?
190
- @object.respond_to?(:to_model) &&
191
- @object.to_model != @object
203
+ object.respond_to?(:to_model) &&
204
+ object.to_model != object
192
205
  end
193
206
  end
@@ -1,25 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector::ObjectInterrogator collaborates with {#object} to return
4
- # Object#{#method_name} if {#object} responds to the method.
3
+ # Collaborates with {#object} to return {#object}#{#method_name} if {#object}
4
+ # responds to {#method_name}.
5
5
  #
6
- # If Object#{#method_name} accepts the supplied `kwargs` then they are passed
6
+ # If {#object}#{#method_name} accepts the supplied `kwargs` then they are passed
7
7
  # in as well. If not, then any supplied `kwargs` will be ignored.
8
- class ObjectInspector::ObjectInterrogator
8
+ class ObjectInspector::InterrogateObject
9
+ def self.call(...) = new(...).call
10
+
9
11
  attr_reader :object,
10
12
  :method_name,
11
13
  :kwargs
12
14
 
13
- def initialize(object:, method_name:, kwargs: {})
15
+ def initialize(object, method_name:, kwargs: {})
14
16
  @object = object
15
17
  @method_name = method_name
16
18
  @kwargs = kwargs
17
19
  end
18
20
 
19
- # @return [String, ...] whatever type Object#{#method_name} returns
21
+ # @return [String, ...] Whatever type Object#{#method_name} returns.
20
22
  #
21
- # @raise [ArgumentError] if Object#{#method_name} has an unexpected method
22
- # signature
23
+ # @raise [ArgumentError] If Object#{#method_name} has an unexpected method
24
+ # signature.
23
25
  def call
24
26
  return unless object_responds_to_method_name?
25
27
 
@@ -40,6 +42,7 @@ class ObjectInspector::ObjectInterrogator
40
42
 
41
43
  # :reek:ManualDispatch
42
44
  # :reek:BooleanParameter
45
+
43
46
  def object_responds_to_method_name?(include_private: true)
44
47
  object.respond_to?(method_name, include_private)
45
48
  end
@@ -2,9 +2,8 @@
2
2
 
3
3
  # :reek:TooManyMethods
4
4
 
5
- # ObjectInspector::Scope defines a predicate method that matches {#names} and
6
- # responds with `true`. This is a prettier way to test for a given type of
7
- # "scope" within objects.
5
+ # Defines a predicate method that matches {#names} and responds with `true`.
6
+ # This is a prettier way to test for a given type of "scope" within objects.
8
7
  #
9
8
  # It is possible to pass in multiple scope names to match on.
10
9
  #
@@ -13,6 +12,16 @@
13
12
  # Passing a block to a scope predicate falls back to the out-of-scope
14
13
  # placeholder (`*` by default) if the scope does not match.
15
14
  #
15
+ # @example
16
+ # ObjectInspector::Scope.new
17
+ # # => <ObjectInspector::Scope :: ["self"]>
18
+ #
19
+ # ObjectInspector::Scope.new(:my_custom_scope)
20
+ # # => <ObjectInspector::Scope :: ["my_custom_scope"]>
21
+ #
22
+ # ObjectInspector::Scope.new(%w[verbose complex])
23
+ # # => <ObjectInspector::Scope :: ["complex", "verbose"]>
24
+ #
16
25
  # @see ActiveSupport::StringInquirer
17
26
  # http://api.rubyonrails.org/classes/ActiveSupport/StringInquirer.html
18
27
  #
@@ -20,8 +29,11 @@
20
29
  class ObjectInspector::Scope
21
30
  attr_reader :names
22
31
 
23
- def initialize(names = %w[self])
24
- @names = Array(names).map { |name| String(name) }
32
+ # :reek:FeatureEnvy
33
+
34
+ def initialize(*names)
35
+ names = names.empty? ? %w[self] : names.flatten
36
+ @names = names.map! { |name| String(name) }.sort!
25
37
  end
26
38
 
27
39
  # Join the passed in name parts with the passed in separator.
@@ -29,7 +41,9 @@ class ObjectInspector::Scope
29
41
  # @param parts [Array<#to_s>]
30
42
  # @param separator [#to_s] (ObjectInspector.configuration.flags_separator)
31
43
  def join_name(
32
- parts, separator: ObjectInspector.configuration.name_separator)
44
+ parts,
45
+ separator: ObjectInspector.configuration.name_separator
46
+ )
33
47
  _join(parts, separator)
34
48
  end
35
49
 
@@ -38,7 +52,9 @@ class ObjectInspector::Scope
38
52
  # @param flags [Array<#to_s>]
39
53
  # @param separator [#to_s] (ObjectInspector.configuration.flags_separator)
40
54
  def join_flags(
41
- flags, separator: ObjectInspector.configuration.flags_separator)
55
+ flags,
56
+ separator: ObjectInspector.configuration.flags_separator
57
+ )
42
58
  _join(flags, separator)
43
59
  end
44
60
 
@@ -47,7 +63,9 @@ class ObjectInspector::Scope
47
63
  # @param issues [Array<#to_s>]
48
64
  # @param separator [#to_s] (ObjectInspector.configuration.issues_separator)
49
65
  def join_issues(
50
- issues, separator: ObjectInspector.configuration.issues_separator)
66
+ issues,
67
+ separator: ObjectInspector.configuration.issues_separator
68
+ )
51
69
  _join(issues, separator)
52
70
  end
53
71
 
@@ -56,19 +74,21 @@ class ObjectInspector::Scope
56
74
  # @param items [Array<#to_s>]
57
75
  # @param separator [#to_s] (ObjectInspector.configuration.info_separator)
58
76
  def join_info(
59
- items, separator: ObjectInspector.configuration.info_separator)
77
+ items,
78
+ separator: ObjectInspector.configuration.info_separator
79
+ )
60
80
  _join(items, separator)
61
81
  end
62
82
 
63
83
  # Compare self with the passed in object.
64
84
  #
65
- # @return [TrueClass] if self and `other` resolve to the same set of objects
66
- # @return [FalseClass] if self and `other` resolve to a different set of
67
- # objects
85
+ # @return [TrueClass] If self and `other` resolve to the same set of objects.
86
+ # @return [FalseClass] If self and `other` resolve to a different set of
87
+ # objects.
68
88
  def ==(other)
69
- @names.sort == Array(other).map(&:to_s).sort!
89
+ names == Array(other).map(&:to_s).sort!
70
90
  end
71
- alias_method :eql?, :==
91
+ alias eql? ==
72
92
 
73
93
  # @return [String] the contents of {#names}, joined by `, `.
74
94
  def to_s(separator: ", ")
@@ -80,6 +100,10 @@ class ObjectInspector::Scope
80
100
  names
81
101
  end
82
102
 
103
+ def inspect
104
+ "<#{self.class.name} :: #{names.inspect}>"
105
+ end
106
+
83
107
  private
84
108
 
85
109
  def method_missing(method_name, *args, &)
@@ -131,10 +155,11 @@ class ObjectInspector::Scope
131
155
  end
132
156
 
133
157
  def any_names_match?(other_name)
134
- @names.any?(other_name)
158
+ names.any?(other_name)
135
159
  end
136
160
 
137
161
  # :reek:BooleanParameter
162
+
138
163
  def respond_to_missing?(method_name, include_private = false)
139
164
  method_name[-1] == "?" || super
140
165
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :reek:IrresponsibleModule
4
+
3
5
  module ObjectInspector
4
6
  # The current ObjectInspector gem version.
5
- VERSION = "0.10.0"
7
+ VERSION = "1.0.0"
8
+ public_constant :VERSION
6
9
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ObjectInspector is the base namespace for all modules/classes related to the
3
+ # Defines the base namespace for all modules/classes used by the
4
4
  # object_inspector gem.
5
5
  module ObjectInspector
6
6
  # Accessor for the {ObjectInspector::Configuration} object.
@@ -19,11 +19,11 @@ module ObjectInspector
19
19
  @configuration = Configuration.new
20
20
  end
21
21
 
22
+ # :reek:TooManyInstanceVariables
23
+
22
24
  # ObjectInspector::Configuration stores the default configuration options for
23
25
  # the ObjectInspector gem. Modification of attributes is possible at any time,
24
26
  # and values will persist for the duration of the running process.
25
- #
26
- # :reek:TooManyInstanceVariables
27
27
  class Configuration
28
28
  attr_reader :formatter_class,
29
29
  :inspect_method_prefix,
@@ -36,7 +36,8 @@ module ObjectInspector
36
36
  :issues_separator,
37
37
  :info_separator
38
38
 
39
- def initialize
39
+ def initialize # rubocop:disable Metrics/MethodLength
40
+ @enabled = true
40
41
  @formatter_class = TemplatingFormatter
41
42
  @inspect_method_prefix = "inspect"
42
43
  @default_scope = Scope.new(:self)
@@ -49,6 +50,21 @@ module ObjectInspector
49
50
  @info_separator = " | "
50
51
  end
51
52
 
53
+ def toggle = enabled? ? disable : enable
54
+ def enabled? = @enabled
55
+
56
+ def enable
57
+ @enabled = true
58
+ puts(" -> ObjectInspector enabled")
59
+ end
60
+
61
+ def disabled? = !enabled?
62
+
63
+ def disable
64
+ @enabled = false
65
+ puts(" -> ObjectInspector disabled")
66
+ end
67
+
52
68
  def formatter_class=(value)
53
69
  unless value.is_a?(Class)
54
70
  raise(TypeError, "Formatter must be a Class constant")
@@ -99,8 +115,8 @@ require "object_inspector/version"
99
115
  require "object_inspector/conversions"
100
116
  require "object_inspector/inspector"
101
117
  require "object_inspector/scope"
102
- require "object_inspector/inspectors_helper"
103
- require "object_inspector/object_interrogator"
118
+ require "object_inspector/inspect_behaviors"
119
+ require "object_inspector/interrogate_object"
104
120
  require "object_inspector/formatters/base_formatter"
105
121
  require "object_inspector/formatters/combining_formatter"
106
122
  require "object_inspector/formatters/templating_formatter"
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.10.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul DobbinSchmaltz
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: benchmark-ips
@@ -82,9 +82,9 @@ files:
82
82
  - lib/object_inspector/formatters/base_formatter.rb
83
83
  - lib/object_inspector/formatters/combining_formatter.rb
84
84
  - lib/object_inspector/formatters/templating_formatter.rb
85
+ - lib/object_inspector/inspect_behaviors.rb
85
86
  - lib/object_inspector/inspector.rb
86
- - lib/object_inspector/inspectors_helper.rb
87
- - lib/object_inspector/object_interrogator.rb
87
+ - lib/object_inspector/interrogate_object.rb
88
88
  - lib/object_inspector/scope.rb
89
89
  - lib/object_inspector/version.rb
90
90
  homepage: https://github.com/pdobb/object_inspector
@@ -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.6
113
+ rubygems_version: 3.7.2
114
114
  specification_version: 4
115
115
  summary: Object Inspector builds uniformly formatted inspect output with customizable
116
116
  amounts of detail.
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # ObjectInspector::InspectorsHelper can be included into any object to
4
- # simplify the process of instantiating an ObjectInspector::Inspector and
5
- # generating the inspection output.
6
- module ObjectInspector::InspectorsHelper
7
- # Calls {ObjectInspector::Inspector.inspect} on the passed in `object`,
8
- # passing through any keyword arguments.
9
- #
10
- # @return [String]
11
- def inspect(object = self, **)
12
- ObjectInspector::Inspector.inspect(object, **)
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
24
- end