3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/client_side_validations/mongoid/uniqueness.rb', line 3
def client_side_hash(model, attribute)
= options.except(*::ActiveModel::Errors::CALLBACKS_OPTIONS - [:on, :allow_blank])
hash = { :message => model.errors.generate_message(attribute, message_type, .except(:case_sensitive, :scope)) }
hash = hash.merge().merge(model.new_record? ? {} : { :id => model.id })
if hash[:scope].present?
hash[:scope] = Array.wrap(hash[:scope]).inject({}) do |scope_hash, scope_item|
scope_hash.merge!(scope_item => model.send(scope_item))
end
else
hash.delete(:scope)
end
hash
end
|