Re: Validation levels: errors, warnings

Michael Schuerig
Sun, 04 May 2008 07:28:56 -0000

On Sunday 04 May 2008, Michael Koziarski wrote:
> >  All of the above can, of course, be easily added to the classes
> > where it is needed, or duck punched into ActiveRecord. What
I''d
> > like to have is a way to use the already existing validations for
> > custom validation levels, too. To be clear, I don''t want any
> > further levels to be added to AR, but I want the necessary hooks to
> > add them myself in an app or plugin.
>
> What kind of hooks do you have in mind?  I''m always a little
suspect
> of adding ''hooks'' for some theoretical future
extensibility, but
> there''s definitely some scope for improving the implementation of
the
> validations.

I''m asking for nothing more than

  record.send(level).add_to_base("Something is wrong")

instead of

  record.errors.add_to_base("Something is wrong")

wherever it applies with level defaulting to :errors, i.e.

  level = options[:level] ?
    options[:level].to_s.pluralize.to_sym :
    :errors