Module: DatabaseValidations::PresenceKeyExtractor

Defined in:
lib/database_validations/lib/presence_key_extractor.rb

Class Method Summary collapse

Class Method Details

.attribute_by_key(validator) ⇒ Hash

Parameters:

Returns:

  • (Hash)


8
9
10
11
12
13
14
15
16
# File 'lib/database_validations/lib/presence_key_extractor.rb', line 8

def attribute_by_key(validator)
  validator.attributes.map do |attribute|
    reflection = validator.klass._reflect_on_association(attribute)

    key = reflection ? reflection.foreign_key : attribute

    [KeyGenerator.for_db_presence(key), attribute]
  end.to_h
end