<commit_before>(ns clj-record.validation
  (:use clj-record.util)
  (:use clj-record.core))


(defn- validations-for [model-name] ((@all-models-metadata model-name) :validations))

(defn validate [model-name record]
  (reduce
    (fn [errors [attr message validation-fn]]
      (if (validation-fn (record attr))
        errors
        (merge-with
          (fn [result addl-val] (apply conj result addl-val))
          errors
          {attr [message]})))
    {}
    (validations-for model-name)))

(defn- validates [model-name attribute-name message function]
  (dosync
    (let [metadata (@all-models-metadata model-name)
          validations (or (@metadata :validations) [])]
      (ref-set metadata
        (assoc @metadata :validations (conj validations [(keyword (name attribute-name)) message (eval function)])))))
  '(identity 1)) ; XXX: Have to return a no-op form since we don't need any defs.<commit_msg>Remove the no-op form returned by validates now that we check for a return value before including anything in the generated init-model expansion.<commit_after>(ns clj-record.validation
  (:use clj-record.util)
  (:use clj-record.core))


(defn- validations-for [model-name] ((@all-models-metadata model-name) :validations))

(defn validate [model-name record]
  (reduce
    (fn [errors [attr message validation-fn]]
      (if (validation-fn (record attr))
        errors
        (merge-with
          (fn [result addl-val] (apply conj result addl-val))
          errors
          {attr [message]})))
    {}
    (validations-for model-name)))

(defn- validates [model-name attribute-name message function]
  (dosync
    (let [metadata (@all-models-metadata model-name)
          validations (or (@metadata :validations) [])]
      (ref-set metadata
        (assoc @metadata :validations (conj validations [(keyword (name attribute-name)) message (eval function)])))))
  nil)
{'fraction_non_alphanumeric': 0.1328745367919534, 'fraction_numerical': 0.0005293806246691371, 'mean_word_length': 3.190687361419069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6241683', 'n_tokens_mistral': 576, 'n_tokens_neox': 562, 'n_words': 173}