fluke/devops-service/db/validators/users_array.rb

18 lines
508 B
Ruby
Raw Normal View History

2018-04-04 22:44:39 +03:00
class UsersArrayValidator < ActiveModel::EachValidator
def validate_each(record, attribute, valueArray)
unless valueArray.empty?
res = begin
users = Devops::Model::User.find(valueArray)#.projection({'_id' => true})
valueArray - users.map{|u| u.id}
rescue Mongoid::Errors::DocumentNotFound
valueArray
end
unless res.empty?
record.errors.add attribute, (options[:message] || "User(s) '#{res.join("', '")}' not found")
end
end
end
end