lib/rasti/form/errors.rb in rasti-form-3.1.2 vs lib/rasti/form/errors.rb in rasti-form-4.0.0
- old
+ new
@@ -1,66 +1,20 @@
module Rasti
class Form
-
- class CastError < StandardError
- attr_reader :type, :value
+ class ValidationError < Rasti::Types::CompoundError
- def initialize(type, value)
- @type = type
- @value = value
- end
+ attr_reader :scope
- 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
+ super errors
end
- def message
- lines = ['Validation errors:']
+ private
- errors.each do |key, value|
- lines << "- #{key}: #{value}"
- end
-
- lines.join("\n")
+ def message_title
+ 'Validation errors:'
end
end
end
\ No newline at end of file