README.md in object_inspector-0.3.1 vs README.md in object_inspector-0.4.0

- old
+ new

@@ -5,11 +5,11 @@ [![Test Coverage](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/test_coverage)](https://codeclimate.com/github/pdobb/object_inspector/test_coverage) [![Maintainability](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/maintainability)](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 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! +Because object inspection code should be uniform, easy to build, and its output should be easy to read! If you'd like to just jump into an example: [Full Example](#full-example). ## Installation @@ -36,11 +36,13 @@ * 2.3.7 * 2.4.4 * 2.5.1 * edge +ObjectInspector has no other dependencies. + ## Configuration Global/default values for ObjectInspector can be configured via the ObjectInspector::Configuration object. _Note: In a Rails app, the following would go in e.g. `config/initializers/object_inspector.rb`_ @@ -48,10 +50,11 @@ ```ruby # Default values are shown. ObjectInspector.configure do |config| 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.flags_separator = " / " config.info_separator = " | " end @@ -75,11 +78,11 @@ See also [Helper Usage](#helper-usage) for an even simpler usage option. ### Output Customization -Use the `identification`, `flags`, `info`, and `name` options to customize inspect output. +Use the `identification`, `flags`, `info`, and/or `name` options to customize inspect output. ```ruby class MyObject def inspect ObjectInspector::Inspector.inspect(self, @@ -294,13 +297,10 @@ end end my_object = MyObject.new("Name") -my_object.inspect -# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | * :: Name>" - my_object.inspect(scope: :complex) # => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | Complex Info | * :: Name>" my_object.inspect(scope: :verbose) # => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Verbose Info :: Name>" @@ -308,10 +308,24 @@ my_object.inspect(scope: %i[self complex verbose]) # => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) 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>" + +my_object.inspect +# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | * :: Name>" + +ObjectInspector.configuration.default_scope = :complex +my_object.inspect +# => "<MyObject[a2:2](DEFAULT_FLAG / *) Default Info | Complex Info | * :: Name>" + +ObjectInspector.configuration.default_scope = %i[self complex verbose] +my_object.inspect + +ObjectInspector.configuration.default_scope = :all +my_object.inspect +# => "<MyObject[a2:2](DEFAULT_FLAG / AO1_FLAG1 / AO2_FLAG1) Default Info | Complex Info | Verbose Info :: Name>" ``` ## Wrapped Objects @@ -396,10 +410,42 @@ See examples: - [ObjectInspector::TemplatingFormatter] - [ObjectInspector::CombiningFormatter] +## Supporting Gems + +ObjectInspector works great with the [ObjectIdentifier](https://github.com/pdobb/object_identifier) gem. + +```ruby +class MyObject + include ObjectInspector::InspectorsHelper + + def my_method1 + 1 + end + + def my_method2 + 2 + end + +private + + def inspect_identification + identify(:my_method1, :my_method2) + end + + def inspect_flags; "FLAG1 / FLAG2" 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>" +``` + + ## Performance ### Benchmarking ObjectInspector ObjectInspetor is ~4x slower than Ruby's default inspect. @@ -448,41 +494,9 @@ # MyCustomFormatter: 52001.2 i/s # ObjectInspector::TemplatingFormatter: 49854.2 i/s - same-ish: difference falls within error # ObjectInspector::CombiningFormatter: 38963.5 i/s - 1.33x slower # # == Done -``` - - -## Supporting Gems - -ObjectInspector works great with the [ObjectIdentifier](https://github.com/pdobb/object_identifier) gem. - -```ruby -class MyObject - include ObjectInspector::InspectorsHelper - - def my_method1 - 1 - end - - def my_method2 - 2 - end - -private - - def inspect_identification - identify(:my_method1, :my_method2) - end - - def inspect_flags; "FLAG1 / FLAG2" 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>" ``` ## Development