Module: ClientSideValidations::Mongoid::Uniqueness
- Defined in:
- lib/client_side_validations/mongoid/uniqueness.rb
Instance Method Summary collapse
-
#client_side_hash(model, attribute, _force = nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
Instance Method Details
#client_side_hash(model, attribute, _force = nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/client_side_validations/mongoid/uniqueness.rb', line 7 def client_side_hash(model, attribute, _force = nil) hash = {} hash[:message] = model.errors.(attribute, , .except(:scope)) hash[:case_sensitive] = [:case_sensitive] if .key?(:case_sensitive) hash[:allow_blank] = true if [:allow_blank] hash[:id] = model.id unless model.new_record? if .key?(:scope) && [:scope].present? hash[:scope] = Array.wrap([:scope]).inject({}) do |scope_hash, scope_item| scope_hash.merge!(scope_item => model.send(scope_item)) end end unless model.class.name.demodulize == model.class.name hash[:class] = model.class.name.underscore end hash end |