Skip to content

Commit

Permalink
Add inspection to context and target.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jan 4, 2015
1 parent edb6b91 commit 86830e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/necromancer/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def can?(source, target)
false
end

# Inspect this context
#
# @api public
def inspect
%(#<#{self.class}@#{object_id} @config=#{configuration}>)
end

protected

attr_reader :conversions
Expand Down
7 changes: 7 additions & 0 deletions lib/necromancer/conversion_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def to(target, options = {})
conversion.call(object, options)
end

# Inspect this conversion
#
# @api public
def inspect
%(#<#{self.class}@#{object_id} @object=#{object}, @source=#{detect(object)}>)
end

protected

# Detect object type
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding: utf-8

require 'spec_helper'

RSpec.describe Necromancer, '.inspect' do
subject(:converter) { described_class.new }

it "inspects converter instance" do
expect(converter.inspect).to eq("#<Necromancer::Context@#{converter.object_id} @config=#{converter.configuration}>")
end

it "inspects conversion target" do
conversion = converter.convert(11)
expect(conversion.inspect).to eq("#<Necromancer::ConversionTarget@#{conversion.object_id} @object=11, @source=integer>")
end
end

0 comments on commit 86830e8

Please sign in to comment.