Sha256: 7c26844e73332ae50a879c66449db64236d0d89667c10410094bf3801cb9d97a

Contents?: true

Size: 1.69 KB

Versions: 22

Compression:

Stored size: 1.69 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

class ParamContractError < ContractError
end

class ReturnContractError < ContractError
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

22 entries across 22 versions & 6 rubygems

Version Path
entitlements-app-1.1.0 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-1.0.0 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-0.3.4 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-0.3.1 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-0.3.0 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-0.2.1 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-0.2.1 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-0.2.0 lib/contracts-ruby2/lib/contracts/errors.rb
entitlements-app-0.2.0 lib/contracts-ruby2/lib/contracts/errors.rb
contracts-0.16.1 lib/contracts/errors.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/contracts-0.13.0/lib/contracts/errors.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/contracts-0.16.0/lib/contracts/errors.rb
contracts-0.16.0 lib/contracts/errors.rb
contracts-0.15.0 lib/contracts/errors.rb
contracts-lite-0.14.0 lib/contracts/errors.rb
contracts-0.14.0 lib/contracts/errors.rb
contracts-0.13.0 lib/contracts/errors.rb
contracts-0.12.0 lib/contracts/errors.rb
contracts-0.11.0 lib/contracts/errors.rb
contracts-0.10.1 lib/contracts/errors.rb