Sha256: bc7ac64427fcca1b66d7f8f95ac88c37738e7ba6c4faa740a6e90cb692bcc13c
Contents?: true
Size: 1.6 KB
Versions: 1
Compression:
Stored size: 1.6 KB
Contents
# @private # Base class for Contract errors # # If default failure callback is used it stores failure data class ContractBaseError < ArgumentError attr_reader :data def initialize(message, data) super(message) @data = data end # Used to convert to simple ContractError from other contract errors def to_contract_error self end end # Default contract error # # If default failure callback is used, users normally see only these contract errors class ContractError < ContractBaseError end # @private # Special contract error used internally to detect pattern failure during pattern matching class PatternMatchingError < ContractBaseError # Used to convert to ContractError from PatternMatchingError def to_contract_error ContractError.new(to_s, data) end end # Base invariant violation error class InvariantError < StandardError def to_contract_error self end end module Contracts # Error issued when user haven't included Contracts in original class but used Contract definition in singleton class # # Provides useful description for user of the gem and an example of correct usage. class ContractsNotIncluded < TypeError DEFAULT_MESSAGE = %{In order to use contracts in singleton class, please include Contracts module in original class Example: ```ruby class Example include Contracts # this line is required class << self # you can use `Contract` definition here now end end ```} attr_reader :message alias_method :to_s, :message def initialize(message = DEFAULT_MESSAGE) @message = message end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
contracts-0.8 | lib/contracts/errors.rb |