README.md in object_inspector-0.4.0 vs README.md in object_inspector-0.5.0
- old
+ new
@@ -53,10 +53,12 @@
config.formatter_class = ObjectInspector::TemplatingFormatter
config.inspect_method_prefix = "inspect"
config.default_scope = ObjectInspector::Scope.new(:self)
config.wild_card_scope = "all"
config.out_of_scope_placeholder = "*"
+ config.presenter_inspect_flags = " ⇨ "
+ config.name_separator = " - "
config.flags_separator = " / "
config.info_separator = " | "
end
```
@@ -102,19 +104,21 @@
class MyObject
def inspect
ObjectInspector::Inspector.inspect(self)
end
-private
+ private
def inspect_identification; "My Object" end
def inspect_flags; "FLAG1 / FLAG2" end
+ def inspect_issues; "ISSUE1 | ISSUE2" end
def inspect_info; "INFO" end
def inspect_name; "NAME" end # Or: def display_name; "NAME" end
end
-MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
+MyObject.new.inspect
+# => "<My Object(FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
```
## Helper Usage
@@ -135,33 +139,37 @@
include ObjectInspector::InspectorsHelper
def inspect
super(identification: "My Object",
flags: "FLAG1",
+ issues: "ISSUE1 | ISSUE2",
info: "INFO",
name: "NAME")
end
end
-MyObject.new.inspect # => "<My Object(FLAG1) INFO :: NAME>"
+MyObject.new.inspect
+# => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
```
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) in Object.
```ruby
class MyObject
include ObjectInspector::InspectorsHelper
-private
+ private
def inspect_identification; "My Object" end
def inspect_flags; "FLAG1 / FLAG2" end
+ def inspect_issues; "ISSUE1 | ISSUE2" end
def inspect_info; "INFO" end
def inspect_name; "NAME" end # Or: def display_name; "NAME" end
end
-MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
+MyObject.new.inspect
+# => "<My Object(FLAG1) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
```
## Scopes
@@ -229,15 +237,17 @@
### Scope Joiners
ObjectInspector::Scope also offers helper methods for uniformly joining inspect elements:
+- `join_name` -- Joins name parts with ` - ` by default
- `join_flags` -- Joins flags with ` / ` by default
- `join_info` -- Joins info items with ` | ` by default
```ruby
scope = ObjectInspector::Scope.new(:verbose)
+scope.join_name([1, 2, 3]) # => "1 - 2 - 3"
scope.join_flags([1, 2, 3]) # => "1 / 2 / 3"
scope.join_info([1, 2, 3]) # => "1 | 2 | 3"
```
@@ -261,12 +271,17 @@
def associated_object2
OpenStruct.new(flags: "AO2_FLAG1")
end
-private
+ # Or `def inspect_name`
+ def display_name(scope:)
+ name
+ end
+ private
+
def inspect_identification
identify(:a2)
end
def inspect_flags(scope:)
@@ -281,51 +296,51 @@
}
scope.join_flags(flags)
end
+ def inspect_issues
+ "!!WARNING!!"
+ end
+
def inspect_info(scope:)
info = ["Default Info"]
info << "Complex Info" if scope.complex?
info << scope.verbose? { "Verbose Info" }
scope.join_info(info)
end
-
- # Or `def inspect_name`
- def display_name
- name
- end
end
my_object = MyObject.new("Name")
my_object.inspect(scope: :complex)
-# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | Complex Info | * :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / *) !!!!WARNING!!!! Default Info | Complex Info | * :: Name>"
my_object.inspect(scope: :verbose)
-# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Verbose Info :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!!!WARNING!!!! Default Info | Verbose Info :: Name>"
my_object.inspect(scope: %i[self complex verbose])
-# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Complex Info | Verbose Info :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!!!WARNING!!!! Default Info | Complex Info | Verbose Info :: Name>"
my_object.inspect(scope: :all)
-# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Complex Info | Verbose Info :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!!!WARNING!!!! Default Info | Complex Info | Verbose Info :: Name>"
my_object.inspect
-# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | * :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / *) !!!!WARNING!!!! Default Info | * :: Name>"
ObjectInspector.configuration.default_scope = :complex
my_object.inspect
-# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | Complex Info | * :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / *) !!!!WARNING!!!! Default Info | Complex Info | * :: Name>"
ObjectInspector.configuration.default_scope = %i[self complex verbose]
my_object.inspect
+# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!!!WARNING!!!! Default Info | Complex Info | Verbose Info :: Name>"
ObjectInspector.configuration.default_scope = :all
my_object.inspect
-# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Complex Info | Verbose Info :: Name>"
+# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) !!!!WARNING!!!! Default Info | Complex Info | Verbose Info :: Name>"
```
## Wrapped Objects
@@ -337,19 +352,19 @@
def to_model
@to_model ||= MyWrappedObject.new
end
-private
+ private
def inspect_flags; "WRAPPER_FLAG1" end
end
class MyWrappedObject
include ObjectInspector::InspectorsHelper
-private
+ private
def inspect_flags; "FLAG1 / FLAG2" end
def inspect_info; "INFO" end
end
@@ -426,22 +441,23 @@
def my_method2
2
end
-private
+ private
def inspect_identification
identify(:my_method1, :my_method2)
end
def inspect_flags; "FLAG1 / FLAG2" end
+ def inspect_issues; "ISSUE1 | ISSUE2" end
def inspect_info; "INFO" end
def inspect_name; "NAME" end
end
MyObject.new.inspect
-# => "<MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) INFO :: NAME>"
+# => "<MyObject[my_method1:1, my_method2:2](FLAG1 / FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>"
```
## Performance