Sha256: 1e2727884d02f8701b4fed677bad966d9e01fa1bf787383a5bb545c93c9e3740

Contents?: true

Size: 1.46 KB

Versions: 39

Compression:

Stored size: 1.46 KB

Contents

require 'power_assert/configuration'
require 'io/console/size'

module PowerAssert
  class InspectedValue
    def initialize(value)
      @value = value
    end

    def inspect
      @value
    end
  end
  private_constant :InspectedValue

  class SafeInspectable
    def initialize(value)
      @value = value
    end

    def inspect
      inspected = @value.inspect
      if Encoding.compatible?(Encoding.default_external, inspected)
        inspected
      else
        begin
          "#{inspected.encode(Encoding.default_external)}(#{inspected.encoding})"
        rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
          inspected.force_encoding(Encoding.default_external)
        end
      end
    rescue => e
      "InspectionFailure: #{e.class}: #{e.message.each_line.first}"
    end
  end
  private_constant :SafeInspectable

  class Inspector
    def initialize(value, indent)
      @value = value
      @indent = indent
    end

    def inspect
      if PowerAssert.configuration.colorize_message
        if PowerAssert.configuration.inspector == :pp
          width = [IO.console_size[1] - 1 - @indent, 10].max
          IRB::ColorPrinter.pp(@value, '', width)
        else
          IRB::Color.colorize_code(@value.to_s, ignore_error: true)
        end
      else
        if PowerAssert.configuration.inspector == :pp
          PP.pp(@value, '')
        else
          @value.inspect
        end
      end
    end
  end
  private_constant :Inspector
end

Version data entries

39 entries across 33 versions & 7 rubygems

Version Path
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
whitelabelmachinename-ruby-sdk-3.0.6 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.1/lib/power_assert/inspector.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
power_assert-2.0.1 lib/power_assert/inspector.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
win32-api-1.10.1 vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/power_assert-2.0.0/lib/power_assert/inspector.rb
power_assert-2.0.0 lib/power_assert/inspector.rb