Class: CompletionKit::TenantScopedUniquenessValidator

Inherits:
ActiveRecord::Validations::UniquenessValidator
  • Object
show all
Defined in:
app/validators/completion_kit/tenant_scoped_uniqueness_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'app/validators/completion_kit/tenant_scoped_uniqueness_validator.rb', line 3

def validate_each(record, attribute, value)
  extra = Array(CompletionKit.config.tenant_scope_columns)
  return super if extra.empty? && options[:scope].nil?

  merged = options.merge(
    scope: Array(options[:scope]) + extra,
    attributes: [attribute],
    class: @klass
  )
  self.class.superclass.new(merged).validate(record)
end