On Sunday, March 13, 2016 at 3:45:41 PM UTC-7, Peter Marsh wrote: > > I recently started working with Sequel and I came across a situation where > I wanted to validate that a model value was greater than a certain value.I > have previously worked with ActiveRecord and knew about the > validates_numercaility_of validator there, I noticed that Sequel didn't > have an equivalent so I put together the following PR: > > https://github.com/jeremyevans/sequel/pull/1155 > > It's essentially a port of ActiveRecord's validates_numericality_of > validator, e.g.: > > class Example < Sequel::Model > validates_numericality_of :something, less_than: 123 > end > > > Jeremy Evan's suggested a different API for this validator, and also posed > the question of whether such validations are common enough that they should > be included in Sequel (full details in the PR). The suggested API would > look something like so: > > class Example < Sequel::Model > validates_less_than :something, 123 > end > > > Note that my suggested API is:
validates_less_than 12, :column Argument first, then columns. This is because validations are designed to work with multiple columns: validates_less_than 12, [:column1, :column2] All other validations that take an argument have the argument first and the columns second, and we should follow that for consistency. What do you think? > I haven't had a use for these personally. In most cases when I'm validating a value is greater than something or less than something, I'm doing both, and use validates_includes with a range. However, maybe it's common to just check one end instead of both and these are more useful than I expect. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
