             [clj-money.util :refer [pprint-and-return]])
   (:import clj_money.NotAuthorizedException))
 
-(defn- resource-key
+(defn- get-resource-tag
   "Returns a keyword identifying the type of the resource"
   [resource]
   (let [result (if (keyword? resource)


(defn tag-resource
  "Adds meta data to identity the type of the specified resource"
  [resource type-key]
  (vary-meta resource #(assoc % ::resource-type type-key)))

(def ^:private auth-context (atom {}))

(defn ->context
  [key value]
  (swap! auth-context #(assoc % key value)))


                   3 args
                   2 (concat [(current-authentication)] args)
                   :else (throw (ex-info "Wrong number of arguments. Expected 2 or 3." {:args args})))
        tag (get-resource-tag resource)
        auth-fn (@auth-fns [action tag])]
    (if auth-fn
      (auth-fn
        user
        resource
        @auth-context)
      (throw (ex-info (format "No authorization rule registered for %s %s." action tag)
                      {:action action :resource tag})))))

(defn authorize
  "Raises an error if the current user does not have
