Module: ForemanRemoteExecution::ErrorsFlattener
- Included in:
- JobInvocation, TemplateInvocation
- Defined in:
- app/models/concerns/foreman_remote_execution/errors_flattener.rb
Instance Method Summary collapse
Instance Method Details
#flattened_errors ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/concerns/foreman_remote_execution/errors_flattener.rb', line 7 def flattened_errors errors = Hash.new { |h, k| h[k] = [] } # self.errors is ActiveModel::Errors, not Hash and doesn't have the #each_key method self.errors.attribute_names.each do |key| = self.errors.(key) invalid_objects = invalid_objects_for_attribute(key) if invalid_objects.blank? errors[key] = else invalid_objects.each do |invalid_object| errors.merge!(sub_object_errors(key, invalid_object, )) end end end errors.map { |key, | self.errors.(key, .join(', ')) } end |
#flattened_validation_exception ⇒ Object
3 4 5 |
# File 'app/models/concerns/foreman_remote_execution/errors_flattener.rb', line 3 def flattened_validation_exception ActiveRecord::RecordNotSaved.new(I18n.t('activerecord.errors.messages.record_invalid', :errors => flattened_errors.join(', '))) end |