13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/awesome_translations/handlers/validations_handler.rb', line 13
def translations_for_group(group)
ArrayEnumerator.new do |yielder|
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
raise "No inspector by that name: #{group.name}" unless model_inspector
model_inspector.clazz._validators.each do |attribute_name, validators|
validators.each do |validator|
if validator.is_a?(ActiveModel::Validations::LengthValidator)
translations_for_length_validator(validator, model_inspector, attribute_name, yielder)
elsif validator.is_a?(ActiveModel::Validations::FormatValidator)
translations_for_format_validator(validator, model_inspector, attribute_name, yielder)
elsif validator.is_a?(ActiveRecord::Validations::UniquenessValidator)
translations_for_uniqueness_validator(validator, model_inspector, attribute_name, yielder)
elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator" translations_for_presence_validator(validator, model_inspector, attribute_name, yielder)
elsif validator.class.name == "EmailValidator" translations_for_email_validator(validator, model_inspector, attribute_name, yielder)
elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator" translations_for_confirmation_validator(validator, model_inspector, attribute_name, yielder)
else
Rails.logger.error "Unhandeled validator: #{validator.class.name}"
end
end
end
end
end
|