README.md in object_inspector-0.5.2 vs README.md in object_inspector-0.6.0

- old
+ new

@@ -22,23 +22,22 @@ And then execute: $ bundle -Or install it yourself as: +Or install it yourself: $ gem install object_inspector ## Compatibility Tested MRI Ruby Versions: -* 2.2.10 -* 2.3.7 -* 2.4.4 -* 2.5.3 -* 2.6.1 +* 2.3 +* 2.4 +* 2.5 +* 2.6 * edge ObjectInspector has no other dependencies. @@ -377,9 +376,65 @@ MyWrapperObject.new.inspect # => "<MyWrapperObject(WRAPPER_FLAG1)> ⇨ <MyWrappedObject(FLAG1 / FLAG2) INFO>" ``` This feature is recursive. + + +### Wrapped Delegators + +If the Object being inspected is wrapped by an object that delegates all unknown methods to the wrapped object, then inspect flags will be doubled up. To get around this, redefine the `inspect` method in the Wrapper object e.g. like: + +```ruby +class MyDelegatingWrapperObject + include ObjectInspector::InspectorsHelper + + def initialize(my_object) + @my_object = my_object + end + + def inspect(**kargs) + super(identification: self.class.name, + name: nil, + flags: nil, + info: nil, + issues: nil, + **kargs) + end + + def to_model + @my_object + end + + private + + def method_missing(method_symbol, *args) + @my_object.__send__(method_symbol, *args) + end + + def respond_to_missing?(*args) + @my_object.respond_to?(*args) || super + end +end + +class MyWrappedObject + include ObjectInspector::InspectorsHelper + + def display_name + "WRAPPED_OBJECT_NAME" + end + + private + + def inspect_flags; "FLAG1" end + def inspect_info; "INFO" end + def inspect_issues; "ISSUE1" end + def inspect_name; "NAME" end +end + +MyDelegatingWrapperObject.new(MyWrappedObject.new).inspect +# => "<MyDelegatingWrapperObject> ⇨ <MyWrappedObject(FLAG1) !!ISSUE1!! INFO :: NAME>" +``` ## On-the-fly Inspect Methods When passed as an option (as opposed to being called via an Object-defined method) symbols will be called/evaluated on Object on the fly.