README.md in object_inspector-0.3.0 vs README.md in object_inspector-0.3.1
- old
+ new
@@ -3,13 +3,17 @@
[](https://badge.fury.io/rb/object_inspector)
[](https://travis-ci.org/pdobb/object_inspector)
[](https://codeclimate.com/github/pdobb/object_inspector/test_coverage)
[](https://codeclimate.com/github/pdobb/object_inspector/maintainability)
-ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional self-definable scope option to represent an object in the console, in logging, etc.
+ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional, self-definable scope option to represents objects. Great for the console, logging, etc.
+Because object inspection code should be easy to write and its output should be easy to read!
+If you'd like to just jump into an example: [Full Example](#full-example).
+
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -42,10 +46,12 @@
_Note: In a Rails app, the following would go in e.g. `config/initializers/object_inspector.rb`_
```ruby
# Default values are shown.
ObjectInspector.configure do |config|
+ config.formatter_class = ObjectInspector::TemplatingFormatter
+ config.inspect_method_prefix = "inspect"
config.wild_card_scope = "all"
config.out_of_scope_placeholder = "*"
config.flags_separator = " / "
config.info_separator = " | "
end
@@ -85,11 +91,11 @@
end
MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
```
-Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and `inspect_name` as either public or private methods on Object.
+Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) as either public or private methods on Object.
```ruby
class MyObject
def inspect
ObjectInspector::Inspector.inspect(self)
@@ -98,11 +104,11 @@
private
def inspect_identification; "My Object" end
def inspect_flags; "FLAG1 / FLAG2" end
def inspect_info; "INFO" end
- def inspect_name; "NAME" end
+ def inspect_name; "NAME" end # Or: def display_name; "NAME" end
end
MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
```
@@ -134,11 +140,11 @@
end
MyObject.new.inspect # => "<My Object(FLAG1) INFO :: NAME>"
```
-Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and `inspect_name` (or `display_name`) in Object.
+Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) in Object.
```ruby
class MyObject
include ObjectInspector::InspectorsHelper
@@ -230,26 +236,10 @@
scope.join_flags([1, 2, 3]) # => "1 / 2 / 3"
scope.join_info([1, 2, 3]) # => "1 | 2 | 3"
```
-### Conversion to ObjectInspector::Scope
-
-ObjectInspector::Conversions.Scope() is available for proper conversion to ObjectInspector::Scope objects. Though this should rarely be necessary as conversion is performed automatically when calling `<my_object>.inspect(scope: <scope_name>)`.
-
-```ruby
-ObjectInspector::Conversions.Scope(:self)
-# => #<ObjectInspector::Scope:0x007ff78ab8e7f8 @name="self">
-
-scope = ObjectInspector::Scope.new(:verbose)
-result = ObjectInspector::Conversions.Scope(scope)
-# => #<ObjectInspector::Scope:0x007ff78ac9c140 @name="verbose">
-
-scope.object_id == result.object_id # => true
-```
-
-
## Full Example
```ruby
class MyObject
include ObjectInspector::InspectorsHelper
@@ -376,10 +366,10 @@
```
## Custom Formatters
-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) and then passing that into ObjectInspector::Inspector.new.
+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.
```ruby
class MyCustomFormatter < ObjectInspector::BaseFormatter
def call
"[#{identification} Flags: #{flags} -- Info: #{info} -- Name: #{name}]"