Method: Webhookdb::Postgres::Validations#validates_at_least_one_of

Defined in:
lib/webhookdb/postgres/validations.rb

#validates_at_least_one_of(*cols, predicate: :nil?) ⇒ Object

Ensures that at least one of the passed columns is not nil.



25
26
27
28
29
30
# File 'lib/webhookdb/postgres/validations.rb', line 25

def validates_at_least_one_of(*cols, predicate: :nil?)
  any_truthy = cols.any? { |col| !self[col].send(predicate) }
  return if any_truthy
  msg = "at least one of #{cols.join(', ')} must be not #{predicate.to_s.delete_suffix('?')}"
  self.errors.add(cols.first, msg)
end