class Contracts::DefaultErrorFormatter

Attributes

data[RW]

Public Class Methods

new(data) click to toggle source
# File lib/contracts/error_formatter.rb, line 22
def initialize(data)
  @data = data
end

Public Instance Methods

message() click to toggle source
# File lib/contracts/error_formatter.rb, line 26
def message
  %{#{header}
    Expected: #{expected},
    Actual: #{data[:arg].inspect}
    Value guarded in: #{data[:class]}::#{method_name}
    With Contract: #{data[:contracts]}
    At: #{position} }
end

Private Instance Methods

expected() click to toggle source
# File lib/contracts/error_formatter.rb, line 45
def expected
  Contracts::Formatters::Expected.new(data[:contract]).contract
end
header() click to toggle source
# File lib/contracts/error_formatter.rb, line 37
def header
  if data[:return_value]
    "Contract violation for return value:"
  else
    "Contract violation for argument #{data[:arg_pos]} of #{data[:total_args]}:"
  end
end
method_name() click to toggle source
# File lib/contracts/error_formatter.rb, line 53
def method_name
  Contracts::Support.method_name(data[:method])
end
position() click to toggle source
# File lib/contracts/error_formatter.rb, line 49
def position
  Contracts::Support.method_position(data[:method])
end