fluke/devops-service/db/validators/categories_array.rb
Tim Lianov 03dc3d8d99 v3
2018-04-04 22:44:39 +03:00

16 lines
401 B
Ruby

class CategoriesArrayValidator < ActiveModel::EachValidator
RUN_LIST_REGEX = /\A(role|recipe)\[[\w-]+(::[\w-]+)?\]\Z/
def validate_each(record, attribute, valueArray)
valueArray.each_with_index do |i, category|
unless category.valid?
category.errors.each do |key, value|
record.errors.add "#{attribute}.#{i}.#{key}", value[0]
end
end
end
end
end