class ActiveMocker::ObjectInspect

Public Class Methods

new(class_name, attributes) click to toggle source
# File lib/active_mocker/mock/object_inspect.rb, line 4
def initialize(class_name, attributes)
  @class_name = class_name
  @attributes = attributes
  @string     = create_inspections
end

Public Instance Methods

to_s() click to toggle source
# File lib/active_mocker/mock/object_inspect.rb, line 10
def to_s
  @string
end
to_str() click to toggle source
# File lib/active_mocker/mock/object_inspect.rb, line 14
def to_str
  @string
end

Private Instance Methods

create_inspections() click to toggle source
# File lib/active_mocker/mock/object_inspect.rb, line 20
def create_inspections
  inspection = @attributes.map do |name, value|
    "#{name}: #{object_for_inspect(value)}"
  end
  "#<#{@class_name} #{inspection.compact.join(", ")}>"
end
object_for_inspect(value) click to toggle source
# File lib/active_mocker/mock/object_inspect.rb, line 27
def object_for_inspect(value)
  if value.is_a?(String) && value.length > 50
    "#{value[0, 50]}...".inspect
  elsif value.is_a?(Date) || value.is_a?(Time)
    %("#{value.to_s(:db)}")
  elsif value.is_a?(Array) && value.size > 10
    inspected = value.first(10).inspect
    %(#{inspected[0...-1]}, ...])
  else
    value.inspect
  end
end