Navigation Menu

Skip to content

Commit

Permalink
Docstring additions and edits.
Browse files Browse the repository at this point in the history
  • Loading branch information
duelinmarkers committed Jul 25, 2009
1 parent 8e2341c commit 6b2d8b0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/clj_record/associations.clj
Expand Up @@ -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"))
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion 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
Expand Down
13 changes: 12 additions & 1 deletion 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)))))
5 changes: 3 additions & 2 deletions src/clj_record/core.clj
Expand Up @@ -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*))))
Expand Down

0 comments on commit 6b2d8b0

Please sign in to comment.