Sha256: 552b91b3f8df759b9c500cc50fa5d6a19e51bf006bb82a35c81b4727bafd5e93

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module Rasti
  class Form
    
    class CastError < StandardError

      attr_reader :type, :value

      def initialize(type, value)
        @type = type
        @value = value
      end

      def message
        "Invalid cast: #{display_value} -> #{type}"
      end

      private

      def display_value
        value.is_a?(::String) ? "'#{value}'" : value.inspect
      end

    end


    class MultiCastError < StandardError

      attr_reader :type, :value, :errors
      
      def initialize(type, value, errors)
        @type = type
        @value = value
        @errors = errors
      end

      def message
        "Invalid cast: #{display_value} -> #{type} - #{JSON.dump(errors)}"
      end

      def display_value
        value.is_a?(::String) ? "'#{value}'" : value.inspect
      end

    end

    class ValidationError < StandardError

      attr_reader :scope, :errors
      
      def initialize(scope, errors)
        @scope = scope
        @errors = errors
      end

      def message
        "Validation error: #{scope} #{JSON.dump(errors)}"
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rasti-form-3.1.0 lib/rasti/form/errors.rb
rasti-form-3.0.0 lib/rasti/form/errors.rb
rasti-form-2.2.0 lib/rasti/form/errors.rb
rasti-form-2.1.0 lib/rasti/form/errors.rb
rasti-form-2.0.0 lib/rasti/form/errors.rb