class Contracts::Formatters::Expected
Used to format contracts for the `Expected:` field of error output.
Public Class Methods
new(contract, full: true)
click to toggle source
@param full [Boolean] if false only unique `to_s` values will be output,
non unique values become empty string.
# File lib/contracts/formatters.rb, line 12 def initialize(contract, full: true) @contract, @full = contract, full end
Public Instance Methods
array_contract(array)
click to toggle source
Formats Array contracts.
# File lib/contracts/formatters.rb, line 37 def array_contract(array) @full = true array.map { |v| InspectWrapper.create(contract(v), full: @full) } end
contract(contract = @contract)
click to toggle source
Formats any type of Contract
.
# File lib/contracts/formatters.rb, line 17 def contract(contract = @contract) case contract when Hash hash_contract(contract) when Array array_contract(contract) else InspectWrapper.create(contract, full: @full) end end
hash_contract(hash)
click to toggle source
Formats Hash contracts.
# File lib/contracts/formatters.rb, line 29 def hash_contract(hash) @full = true # Complex values output completely, overriding @full hash.inject({}) do |repr, (k, v)| repr.merge(k => InspectWrapper.create(contract(v), full: @full)) end end