Sha256: 3385c9a736c9d8c288cbefe91122317e3deca0e6216c7df8268408ff8e382f63

Contents?: true

Size: 984 Bytes

Versions: 4

Compression:

Stored size: 984 Bytes

Contents

module Apipie

  class Error < StandardError
  end

  class ParamError < Error
  end

  # abstract
  class DefinedParamError < ParamError
    attr_accessor :param

    def initialize(param)
      @param = param
    end
  end

  class ParamMissing < DefinedParamError
    def to_s
      unless @param.options[:missing_message].nil?
        if @param.options[:missing_message].kind_of?(Proc)
          @param.options[:missing_message].call
        else
          @param.options[:missing_message].to_s
        end
      else
        "Missing parameter #{@param.name}"
      end
    end
  end

  class UnknownParam < DefinedParamError
    def to_s
      "Unknown parameter #{@param}"
    end
  end

  class ParamInvalid < DefinedParamError
    attr_accessor :value, :error

    def initialize(param, value, error)
      super param
      @value = value
      @error = error
    end

    def to_s
      "Invalid parameter '#{@param}' value #{@value.inspect}: #{@error}"
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apipie-rails-0.5.0 lib/apipie/errors.rb
apipie-rails-0.4.0 lib/apipie/errors.rb
apipie-rails-0.3.7 lib/apipie/errors.rb
apipie-rails-0.3.6 lib/apipie/errors.rb