On Sat, Aug 28, 2021 at 8:22 PM [email protected] <[email protected]> wrote:

> OK, understood.  How do I insist on required parameters, named or
> otherwise?
>

Probably easiest to check for values after calling super:

  def initialize(values={})
    super
    raise ArgumentError unless some_criteria
    # ...
  end

Note that this approach makes little sense in Sequel.  In Sequel, you can
do:

 Model.new(values).save

but you can also do:

  Model.new.set(values).save

So checking for values in initialize does not make sense.  Sequel::Model
expects you to override validate and call super:

  def validate
    super
    errors.add(:column1, "doesn't meet criteria") unless some_criteria
  end

validate is called before saving the model.

There are numerous plugins that offer additional validation methods and
approaches.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSd4GLbUMBnNbJR3_gF7oL8or%3DN8MciiHpcQSVQokT6TUA%40mail.gmail.com.

Reply via email to