lib/sequel/plugins/validation_helpers.rb in sequel-5.67.0 vs lib/sequel/plugins/validation_helpers.rb in sequel-5.68.0

- old
+ new

@@ -73,10 +73,14 @@ # private # def full_message(attribute, error_msg) # "#{Array(attribute).join(I18n.t('errors.joiner'))} #{error_msg}" # end # end + # + # It is recommended that users of this plugin that use validates_schema_types also use + # the validation_helpers_generic_type_messages plugin for more useful type validation + # failure messages. module ValidationHelpers DEFAULT_OPTIONS = { :exact_length=>{:message=>lambda{|exact| "is not #{exact} characters"}}, :format=>{:message=>lambda{|with| 'is invalid'}}, :includes=>{:message=>lambda{|set| "is not in range or set: #{set.inspect}"}}, @@ -209,11 +213,11 @@ # the value must be an instance of one of the classes in the array. def validates_type(klass, atts, opts=OPTS) klass = klass.to_s.constantize if klass.is_a?(String) || klass.is_a?(Symbol) validatable_attributes_for_type(:type, atts, opts) do |a,v,m| if klass.is_a?(Array) ? !klass.any?{|kls| v.is_a?(kls)} : !v.is_a?(klass) - validation_error_message(m, klass) + validates_type_error_message(m, klass) end end end # Check attribute value(s) is not considered blank by the database, but allow false values. @@ -336,9 +340,12 @@ # is a Proc, call it with the args. Otherwise, assume it is a string and # return it. def validation_error_message(message, *args) message.is_a?(Proc) ? message.call(*args) : message end + + # The validation error message for type validations, for the given class. + alias validates_type_error_message validation_error_message end end end end