Skip to content

Commit

Permalink
Finalize initial gem release
Browse files Browse the repository at this point in the history
Add SimpleCov gem.
Add CHANGELOG.

Add Gem Version badge to README.
Add Build Status badge to README.
Add Code Climate badge to README.
Add Test Coverage badge to README.
Add Compatibility section to README.
Add Custom Formatters section to README.

Finalize gem description, homepage, etc. in .gemspec

Finalize yard documentation throughout the code.
  • Loading branch information
pdobb committed Apr 10, 2018
1 parent 594c274 commit 5ff79da
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/spec/reports/
/tmp/
.byebug_history
*.gem
.DS_Store
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
env:
global:
- CC_TEST_REPORTER_ID=7711465d4611bd7f1211f3262ac4ba750ffcda0574c3c6e4a6ba55446871dd17
sudo: false
language: ruby
rvm:
- 2.2.8
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
- ruby-head
before_install: gem install bundler -v 1.16.1
cache: bundler
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 0.1.0 - 2018-04-09

* Initial release!
14 changes: 11 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ GEM
specs:
byebug (10.0.2)
coderay (1.1.2)
docile (1.3.0)
json (2.1.0)
method_source (0.9.0)
minitest (5.11.3)
pry (0.11.3)
Expand All @@ -17,18 +19,24 @@ GEM
byebug (~> 10.0)
pry (~> 0.10)
rake (10.4.2)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
byebug
byebug (~> 10.0)
minitest (~> 5.0)
object_inspector!
pry
pry-byebug
pry (~> 0.11)
pry-byebug (~> 3.6)
rake (~> 10.0)
simplecov (~> 0.16)

BUNDLED WITH
1.16.1
79 changes: 77 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ObjectInspector

ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a display name along with a complexity level to represent an object in the console, in logging, or otherwise.
[![Gem Version](https://badge.fury.io/rb/object_inspector.png)](http://badge.fury.io/rb/object_inspector)
[![Build Status](https://travis-ci.org/objects-on-rails/display-case.svg?branch=master)](https://travis-ci.org/objects-on-rails/display-case)
[![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 a self-definable scope option to represent an object in the console, in logging, or otherwise.


## Installation
Expand All @@ -20,6 +25,15 @@ Or install it yourself as:
$ gem install object_inspector


## Compatibility

Tested MRI Ruby Versions:
* 2.2.10
* 2.3.7
* 2.4.4
* 2.5.1


## Usage

Given, an object of any type, call ObjectInspector::Inspect#to_s.
Expand Down Expand Up @@ -51,7 +65,7 @@ See also [Helper Usage](#helper-usage) for an even simpler usage option.

### Output Customization

Use ObjectInspector::Inspector#initialize's `identification`, `flags`, `info`, and `name` options to customize inspect output.
Use ObjectInspector::Inspector#initialize options -- `identification`, `flags`, `info`, and `name` -- to customize inspect output.

```ruby
class MyObject
Expand Down Expand Up @@ -188,6 +202,67 @@ MyObject.new.inspect(scope: :all) # => "<MyObject[FLAG1 / FLAG2]>"
```


## 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/base_formatter.rb) and then passing that into ObjectInspector::Inspector.new.

```ruby
class MyCustomFormatter < ObjectInspector::BaseFormatter
def call
"(#{combine_strings})"
end

private

def build_identification_string(identification = self.identification)
identification.to_s
end

def build_flags_string(flags = self.flags)
" #{flags}" if flags
end

def build_info_string(info = self.info)
" (#{info})" if info
end

def build_name_string(name = self.name)
" -- #{name}" if name
end
end

class MyObject
include ObjectInspector::InspectorsHelper

def inspect
super(formatter: MyCustomFormatter)
end

private

def inspect_identification
"IDENTIFICATION"
end

def inspect_flags
"FLAG1"
end

def inspect_info
"INFO"
end

def inspect_name
"NAME"
end
end

MyObject.new.inspect # => "(IDENTIFICATION FLAG1 (INFO) -- NAME)"
```

See also: [ObjectInspector::DefaultFormatter](https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/default_formatter.rb).


## Supporting Libraries

ObjectInspector works great with the [ObjectIdentifier](https://github.com/pdobb/object_identifier) gem.
Expand Down
2 changes: 2 additions & 0 deletions lib/object_inspector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "object_inspector/version"

# ObjectInspector is the base namespace for all modules/classes related to the
# object_inspector gem.
module ObjectInspector
autoload :Inspector, "object_inspector/inspector"
autoload :ObjectInterrogator, "object_inspector/object_interrogator"
Expand Down
17 changes: 14 additions & 3 deletions lib/object_inspector/base_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
module ObjectInspector
# ObjectInspector::BaseFormatter is an abstract base class that interfaces
# with ObjectInspector::Inspector objects to combine the supplied
# with {ObjectInspector::Inspector} objects to combine the supplied
# {#identification}, {#flags}, {#info}, and {#name} strings into a friendly
# "inspect" String.
#
# @attr inspector [ObjectInspector::Inspector] the object from which Strings
# are queried for building the formatted inspect String
# @attr inspector [ObjectInspector::Inspector]
class BaseFormatter
attr_reader :inspector

def initialize(inspector)
@inspector = inspector
end

# Perform the formatting routine.
#
# @return [String]
def call
raise NotImplementedError
end

# Delegates to {Inspector#identification}.
#
# @return [String] if given
def identification
@inspector.identification
end

# Delegates to {Inspector#flags}.
#
# @return [String] if given
# @return [NilClass] if not given
def flags
@inspector.flags
end

# Delegates to {Inspector#info}.
#
# @return [String] if given
# @return [NilClass] if not given
def info
@inspector.info
end

# Delegates to {Inspector#name}.
#
# @return [String] if given
# @return [NilClass] if not given
def name
Expand Down
3 changes: 3 additions & 0 deletions lib/object_inspector/default_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module ObjectInspector
#
# @attr (see BaseFormatter)
class DefaultFormatter < BaseFormatter
# Perform the formatting routine.
#
# @return [String]
def call
"<#{combine_strings}>"
end
Expand Down
25 changes: 20 additions & 5 deletions lib/object_inspector/inspector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ObjectInspector
# ObjectInspector::Inspector organizes inspection of the associated {#object}.
# ObjectInspector organizes inspection of the associated {#object} via the
# passed in options and via a {ObjectInspector::BaseFormatter} instance.
#
# @attr object [Object] the object being inspected
# @attr scope [Symbol] Object inspection type. For example:
Expand All @@ -8,20 +9,23 @@ module ObjectInspector
# :all -- Means: Interrogate self as well as neighboring objects
# <custom> -- Any value that {#object} recognizes can mean anything
# that makes sense for {#object}
# @attr formatter [BaseFormatter] the formatter object to use for combining
# the output of into the inspect String
# @attr formatter [ObjectInspector::BaseFormatter] the formatter object to use
# for combining the output of into the inspect String
# @attr kargs [Hash] options to be sent to {#object}
class Inspector
attr_reader :object,
:scope,
:formatter_klass,
:kargs

# The prefix for all methods called on {#object} for inspect
# details/strings.
def self.object_method_prefix
"inspect".freeze
end

# ObjectInspector::Inspector.inspect shortcuts the instantiation and {#to_s}
# flow that would normally be required to use ObjectInspector::Inspector.
# Shortcuts the instantiation -> {#to_s} flow that would normally be
# required to use ObjectInspector::Inspector.
#
# @return [String]
def self.inspect(object, **kargs)
Expand All @@ -39,27 +43,38 @@ def initialize(
@kargs = kargs
end

# Generate the formatted inspect String.
#
# @return [String]
def to_s
formatter.call
end

# Core object identification details, such as the {#object} class name and
# any core-level attributes.
#
# @return [String]
def identification
(value(key: :identification) || object.class).to_s
end

# Boolean flags/states applicable to {#object}.
#
# @return [String] if given
# @return [NilClass] if not given
def flags
value(key: :flags)
end

# Informational details applicable to {#object}.
#
# @return [String] if given
# @return [NilClass] if not given
def info
value(key: :info)
end

# The generally human-friendly unique identifier for {#object}.
# @return [String] if given
# @return [NilClass] if not given
def name
Expand Down
4 changes: 2 additions & 2 deletions lib/object_inspector/inspectors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module ObjectInspector
# simplify the process of instantiating an ObjectInspector::Inspector and
# generating the inspection output.
module InspectorsHelper
# Calls {Inspector.inspect} on the passed in `object`, passing it the passed
# in `kargs` (keyword arguments).
# Calls {ObjectInspector::Inspector.inspect} on the passed in `object`,
# passing it the passed in `kargs` (keyword arguments).
#
# @return [String]
def inspect(object = self, **kargs)
Expand Down
25 changes: 13 additions & 12 deletions object_inspector.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ Gem::Specification.new do |spec|
spec.authors = ["Paul Dobbins"]
spec.email = ["paul.dobbins@icloud.com"]

spec.summary = %q{ObjectInspector generates uniform inspect output with varying amounts of detail.}
spec.description = %q{ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a display name along with a complexity level to represent an object in the console, in logging, or otherwise.}
spec.homepage = ""
spec.summary = %q{ObjectInspector generates uniformly formatted inspect output with customizable amounts of detail.}
spec.description = %q{ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with a self-definable scope option to represent an object in the console, in logging, or otherwise.}
spec.homepage = "https://github.com/pdobb/object_inspector"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
# if spec.respond_to?(:metadata)
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
# else
# raise "RubyGems 2.0 or newer is required to protect against " \
# "public gem pushes."
# end

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
Expand All @@ -33,7 +33,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "byebug"
spec.add_development_dependency "pry"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "simplecov", "~> 0.16"
spec.add_development_dependency "byebug", "~> 10.0"
spec.add_development_dependency "pry", "~> 0.11"
spec.add_development_dependency "pry-byebug", "~> 3.6"
end
7 changes: 7 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
require "simplecov"
SimpleCov.start do
add_filter "/bin/"
add_filter "/test/"
end
puts "SimpleCov enabled."

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "object_inspector"

Expand Down

0 comments on commit 5ff79da

Please sign in to comment.