Method: Webhookdb::Postgres::Validations#validates_mutually_exclusive
- Defined in:
- lib/webhookdb/postgres/validations.rb
#validates_mutually_exclusive(*cols, predicate: :nil?) ⇒ Object
Ensures that only one of the passed columns is not nil.
7 8 9 10 11 12 |
# File 'lib/webhookdb/postgres/validations.rb', line 7 def validates_mutually_exclusive(*cols, predicate: :nil?) truthy_cols = cols.find_all { |col| !self[col].send(predicate) } multiple_set = truthy_cols.length > 1 return unless multiple_set self.errors.add(truthy_cols.first, "is mutually exclusive with other set columns #{truthy_cols[1..].join(', ')}") end |