Module: ClientSideValidations::ActiveModel::Validations

Defined in:
lib/client_side_validations/active_model.rb

Instance Method Summary collapse

Instance Method Details

#client_side_validation_hashObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/client_side_validations/active_model.rb', line 19

def client_side_validation_hash
  _validators.except(nil).inject({}) do |attr_hash, attr|

    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))
        kind_hash.merge!(validator.kind => client_side_hash.except(:on))
      else
        kind_hash.merge!({})
      end
    end

    attr_hash.merge!(attr[0] => validator_hash)
  end.delete_if { |key, value| value.blank? }
end