Module: BlindIndex::Extensions::UniquenessValidator

Defined in:
lib/blind_index/extensions.rb

Instance Method Summary collapse

Instance Method Details

#build_relation(klass, attribute, value) ⇒ Object

change attribute name here instead of validate_each for better error message



40
41
42
43
44
45
# File 'lib/blind_index/extensions.rb', line 40

def build_relation(klass, attribute, value)
  if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
    attribute = bi[:bidx_attribute]
  end
  super(klass, attribute, value)
end

#validate_each(record, attribute, value) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/blind_index/extensions.rb', line 31

def validate_each(record, attribute, value)
  klass = record.class
  if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
    value = record.read_attribute_for_validation(bi[:bidx_attribute])
  end
  super(record, attribute, value)
end