Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Docstring additions and edits.

  • Loading branch information...
commit 6b2d8b0a49b07a9ac91438f12ff8d1338f547949 1 parent 8e2341c
@duelinmarkers authored
View
14 src/clj_record/associations.clj
@@ -9,10 +9,11 @@
(assoc-fn model-name association-name)))
(defn has-many
- "Called indirectly via clj-record.core/init-model.
- Defines an association to a model whose name is infered by singularizing association-name.
+ "Defines an association to a model whose name is infered by singularizing association-name.
In ns foo's init-model, (has-many bars) will define find-bars and destroy-bars functions in foo,
- each of which take a foo record and find or destroy bars by {:foo_id (record :id)}."
+ each of which take a foo record and find or destroy bars by {:foo_id (record :id)}.
+
+ Called indirectly via clj-record.core/init-model."
[model-name association-name]
(let [associated-model-name (singularize (name association-name))
foreign-key-attribute (keyword (str model-name "_id"))
@@ -25,9 +26,10 @@
(clj-record.core/destroy-records ~associated-model-name {~foreign-key-attribute (record# :id)})))))
(defn belongs-to
- "Called indirectly via clj-record.core/init-model.
- Defines an association to a model named association-name.
- In ns bar's init-model, (belongs-to foo) will define find-foo in bar."
+ "Defines an association to a model named association-name.
+ In ns bar's init-model, (belongs-to foo) will define find-foo in bar.
+
+ Called indirectly via clj-record.core/init-model."
[model-name association-name]
(let [associated-model-name (str association-name)
find-fn-name (symbol (str "find-" associated-model-name))
View
4 src/clj_record/boot.clj
@@ -1,4 +1,6 @@
-(ns clj-record.boot
+(ns
+ #^{:doc "Requiring this one namespace will require everything needed to use clj-record."}
+ clj-record.boot
(:require (clj-record
core
callbacks
View
13 src/clj_record/callbacks/built_ins.clj
@@ -1,6 +1,17 @@
(ns clj-record.callbacks.built-ins)
-(defn transform-value [attribute func]
+(defn transform-value
+ "Given an attribute name and a function, creates a callback function that
+ uses the given function to transform the named attribute in a record.
+
+ Assuming clj-record.callbacks.built-ins has been aliased to cb,
+ you might do this in an init-model form:
+
+ ...
+ (:callbacks
+ (:before-save (cb/transform-value :save-count inc)))
+ ..."
+ [attribute func]
(fn [record]
(assoc record attribute (func (record attribute)))))
View
5 src/clj_record/core.clj
@@ -148,11 +148,12 @@
[top-level-options remaining-options])))
(defmacro init-model
- "Macro to turn a namespace into a 'model.'
+ "Macro to create a model out of a clojure namespace.
The segment of the namespace name following the last dot is used as the model-name.
Model-specific versions of most public functions in clj-record.core are defined
- in the model namespace (where the model-name as first argument can be omitted).
+ in the model namespace (minus the model-name as first argument).
Optional forms for associations and validation are specified here.
+
See clj_record/test/model/manufacturer.clj for an example."
[& init-options]
(let [model-name (last (str-utils/re-split #"\." (name (ns-name *ns*))))
Please sign in to comment.
Something went wrong with that request. Please try again.