Module: ClientSideValidations::ActiveModel::Validations

Defined in:
lib/client_side_validations/active_model.rb

Instance Method Summary collapse

Instance Method Details

#client_side_validation_hashObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/client_side_validations/active_model.rb', line 23

def client_side_validation_hash
  @client_side_validation_hash ||= _validators.inject({}) do |attr_hash, attr|
    unless [nil, :block].include?(attr[0])

      validator_hash = attr[1].inject({}) do |kind_hash, validator|
        client_side_hash = validator.client_side_hash(self, attr[0])
        # Yeah yeah, #new_record? is not part of ActiveModel :p
        if can_use_for_client_side_validation?(client_side_hash, validator) && uniqueness_validations_allowed_or_not_applicable?(validator)
          kind_hash.merge!(validator.kind => client_side_hash.except(:on))
        else
          kind_hash.merge!({})
        end
      end

      if validator_hash.present?
        attr_hash.merge!(attr[0] => validator_hash)
      else
        attr_hash
      end
    else
      attr_hash
    end
  end
end