Skip to content

Commit

Permalink
Use Potemkin to define model record types in defmodel macro (#69)
Browse files Browse the repository at this point in the history
* Use Potemkin to define model record types in defmodel macro

* Lint fix 🔧 👕
  • Loading branch information
camsaul authored Oct 21, 2019
1 parent 1e5e1b0 commit cc388d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject toucan "1.14.1"
(defproject toucan "1.15"
:description "Functionality for defining your application's models and querying the database."
:url "https://github.com/metabase/toucan"
:license {:name "Eclipse Public License"
Expand All @@ -22,7 +22,8 @@
[org.clojure/java.jdbc "0.7.10"]
[org.clojure/tools.logging "0.5.0"]
[org.clojure/tools.namespace "0.3.1"]
[honeysql "0.9.8"]]
[honeysql "0.9.8"]
[potemkin "0.4.5"]]

:profiles
{:dev
Expand Down
7 changes: 4 additions & 3 deletions src/toucan/models.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
the `IModel` protocol and default implementations, which implement Toucan model functionality."
(:require [clojure.walk :refer [postwalk]]
[honeysql.format :as hformat]
[potemkin.types :as p.types]
[toucan.util :as u])
(:import honeysql.format.ToSql))

Expand Down Expand Up @@ -174,7 +175,7 @@
;;; IModel Interface
;;; ==================================================================================================================

(defprotocol IModel
(p.types/defprotocol+ IModel
"The `IModel` protocol defines the various methods that are used to provide custom behavior for various models.
This protocol contains the various methods model classes can optionally implement. All methods have a default
Expand Down Expand Up @@ -312,7 +313,7 @@
:else (recur obj more)))))


(defprotocol ICreateFromMap
(p.types/defprotocol+ ICreateFromMap
"Used by internal functions like `do-post-select`."
(^:private map-> [klass, ^clojure.lang.IPersistentMap m]
"Convert map M to instance of record type KLASS."))
Expand Down Expand Up @@ -489,7 +490,7 @@
(drop 1 args))
instance (symbol (str model "Instance"))
map->instance (symbol (str "map->" instance))
defrecord-form `(defrecord ~instance []
defrecord-form `(p.types/defrecord+ ~instance []
clojure.lang.Named
(~'getName [~'_] ~(name model))
(~'getNamespace [~'_] ~(name (ns-name *ns*)))
Expand Down
5 changes: 3 additions & 2 deletions src/toucan/util/test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns toucan.util.test
"Utility functions for writing tests with Toucan models."
(:require [toucan.db :as db]))
(:require [potemkin.types :as p.types]
[toucan.db :as db]))

;;; TEMP OBJECTS
;;; ==================================================================================================================
Expand Down Expand Up @@ -68,7 +69,7 @@
;; similar macros for other unit test frameworks are welcome!)


(defprotocol WithTempDefaults
(p.types/defprotocol+ WithTempDefaults
"Protocol defining the `with-temp-defaults` method, which provides default values for new temporary objects."
(with-temp-defaults ^clojure.lang.IPersistentMap [this]
"Return a map of default values that should be used when creating a new temporary object of this model.
Expand Down

0 comments on commit cc388d1

Please sign in to comment.