   [namespace]
   (remove nil?
           (map #(get-function-meta namespace %) (ns-paths namespace))))
-
-;(defn describe-context [context-path [path args namespace & contexts]]
-;  (let [new-context-path (str context-path path)
-;        handlers (scan-namespace-for-doc namespace)]
-;    (cons
-;      (desc/resource new-context-path namespace (ns-validation namespace) handlers)
-;      (map (partial describe-context new-context-path) contexts))))
-;
-;(defn doc-route-uncached [service contexts]
-;  (compojure/make-route :get "/"
-;                             (fn [request]
-;                               (let [html (desc/resource-page service
-;                                                              (map (partial describe-context "") contexts))]
-;                                 {:body html}))))
-;
-;(def doc-route (memo/memo doc-route-uncached))
-;
-;;if we want to namespace-specific for the cache, we will require a newer version of clojure.core.memoize
-;(defn clear-namespace-cache!
-;  "Clear namespace cache, forcing a re-scan of every namespace checked."
-;  []
-;  (memo/memo-clear! scan-namespace)
-;  (memo/memo-clear! doc-route))
-
-;(defn make-namespace-handler
-;  "Create a namespace handler, which will scan a namespace (cached) for functions matching the naming convention.
-;   <auths> should be a map of auth types to functions of request and permissions returning a ring response map."
-;  [namespace auths env service services]
-;  (fn [request]
-;    (apply compojure/routing request (scan-namespace namespace auths env service services))))
-;
-;(defn make-doc-handler
-;  "Create a namespace documention handler, which will scan namespaces (cached) for functions matching the naming convention."
-;  [service & contexts]
-;  (fn [request]
-;    (compojure/routing request (doc-route service contexts))))
-;
-;(defn resources [env service services auths contexts]
-;  (when (seq contexts)
-;    (doall (map (fn [[path args namespace & contexts]]
-;                  `(compojure/context ~path ~args
-;                                 (make-namespace-handler ~namespace ~auths ~env ~service ~services)
-;                                 ~@(resources env service services auths contexts)))
-;                contexts))))
-;
-;(defmacro routes
-;  "Creates compojure routes for the given <contexts>
-;   Each context should be of the form [<path> <args> <namespace> <context>*] where:
-;    * path is the context path (string) as supplied to compojure.core/context
-;    * args is a set of bindings as supplied to compojure.core/context
-;    * namespace is the namespace to scan for handlers
-;    * context is zero or more nested contexts
-;   <env> :environment setting from main conf
-;   <service> keyword identifying specific map in services
-;   <services> map of services, used to determine how to connect to other services
-;   <auths> should be a map of auth types to functions of request and permissions returning a ring response map
-;
-;   If :auth is specified in handler metadata it is used to lookup the auth function in <auths>, otherwise :default is used."
-;  [env service services auths & contexts]
-;  `(compojure/routes
-;     (make-doc-handler ~service ~@contexts)
-;     ~@(resources env service services auths contexts)))
 
 (defn build-map-arg-resolver [& kvs]
   (let [arg-map (apply hash-map kvs)]

    (when (symbol-for-function? f) ;it has to be a function all right
      f)))

;(defn- ns-validation
;  "Return the validation for the given namespance and action keyword (:create, :update).
;   Disables :required validations for :update actions"
;  [namespace action]
;  (when-let [v (ns-resolve namespace (symbol "validation"))]
;    (condp = action
;      :create (deref v)
;      :update (walk/postwalk-replace {[:required true] [:required false]} (deref v)))))

;(defn route-function-wrapper
;  [processors arg-resolvers namespace f]
;  (fn [request]
;    (if-let [processor (first processors)]
;      ((mw namespace (meta f) (processors-wrapper (rest processors) arg-resolvers namespace f))
;        request)
;      (invoke-handler-function f (-> f meta :arglists first)  request))))

;(defn create-function-route-handler
;  "Create a handler for a route which invokes function <f> after parsing and validation of request data (if :validate? metadata is true)
;   The function is invoked with arguments as determined by extract-param-value.
;   The request is augmented with an :env entry containing a map of :mode, :service and :services."
;  [namespace f default-middlewares default-arg-resolvers]
;  (let [{:keys [middlewares arg-resolvers arglists] :as meta-data} (meta f)]
;    (fn [request]
;      (let [request (assoc request
;                      :rook {:namespace namespace
;                             :function f
;                             :metadata meta-data
;                             :arg-resolvers (concat default-arg-resolvers arg-resolvers)})
;            rook-wrapper (route-function-wrapper (concat default-middlewares middlewares))]
;        (rook-wrapper request)))))

;    (fn [request]
;      (l/debugf "Request %s: %s" (:request-method request) (:uri request))
;          (v/validate-and-process request validation
                                  ; Add data (transformed and validated) as another option for params
;                                  (partial invoke-handler-function f (first arglists) request))
;          (invoke-handler-function f (first arglists) request nil))))))

(defn- success?
  [{:keys [status]}]
  (<= 200 status 399))

;(defn wrap-auth
;  "Ring middleware which authorizes the request by calling <auth-fn> with the request and <permissions> (a collections of permission strings or a function of the request, returning same)
;    * <handler> is called if auth is successful (auth-fn returns a 2xx status response)
;    * Otherwise the response from the auth-fn is returned as-is
;   If <auth-fn> is nil then handler is always invoked."
;  [handler auth-fn permissions]
;  (fn [request]
;    (if auth-fn
;      (let [permissions (if (fn? permissions) (permissions request) permissions)
;            auth-response (auth-fn request permissions)]
;        (if (success? auth-response)
;          (handler request)
;          auth-response))
;      (handler request))))

;(defn make-function-route
;  "Create function route from route-mapping and namespace."
;  [namespace [path-spec function-key] default-processors default-arg-resolvers]
;  (when-let [f (ns-function namespace function-key)]
;    (let [[method path] path-spec
;;          permissions (:permissions (meta f))
;;          auth (or (:auth (meta f)) :default)
;;          auth-fn (get auths auth)
;          handler (create-function-route-handler namespace f default-processors default-arg-resolvers)]
;;      (l/infof "Building route for %s with %s" [path-spec function-key] (l/pprint-str (select-keys (meta f) [:auth :permissions :path-spec :name])))
;      (compojure/make-route method path
;;                                 (wrap-auth handler auth-fn permissions)
;                                 handler
;                                 ))))


(defn function-entry
  "Create function entry if it has :path-spec defined in its metadata, for example:

                 (filter symbol-for-function? (map second (ns-publics namespace)))))
    DEFAULT-MAPPINGS))

(defn get-function-meta
  "Get meta for route-mapping and namespace."
  [namespace [path-spec function-key]]
