Sha256: 2414d7cb581251e7bf1edb765f4c2e94093d6d33aea9bdaee14cf05a2f6b3053

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

module ActiveMock
class ObjectInspect

  def initialize(class_name, attributes)
    @class_name = class_name
    @attributes = attributes
    @string     = create_inspections
  end

  def to_s
    @string
  end

  def to_str
    @string
  end

  private

  def create_inspections
    inspection = @attributes.map do |name ,value|
      "#{name}: #{object_for_inspect(value)}"
    end
    "#<#{@class_name} #{inspection.compact.join(", ")}>"
  end

  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

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_mocker-1.4.2 lib/active_mock/object_inspect.rb