From 3b4a9d03103bcc8f8461842a2658b94e996bf9c0 Mon Sep 17 00:00:00 2001 From: Cam Saul Date: Wed, 31 Aug 2022 16:29:11 -0700 Subject: [PATCH 1/3] *Disable* color if NO_COLOR is set to true --- src/methodical/util/trace.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/methodical/util/trace.clj b/src/methodical/util/trace.clj index 6daab9d..7c5df92 100644 --- a/src/methodical/util/trace.clj +++ b/src/methodical/util/trace.clj @@ -8,7 +8,7 @@ (def ^:dynamic *color* "Whether or not to print the trace in color. True by default, unless the env var `NO_COLOR` is true." (if-let [env-var-value (System/getenv "NO_COLOR")] - (Boolean/parseBoolean env-var-value) + (complement (Boolean/parseBoolean env-var-value)) true)) (def ^:dynamic *pprinter* From 6b072eab86d649e79e961e1ce93219e79927c5f2 Mon Sep 17 00:00:00 2001 From: Cam Saul Date: Thu, 1 Sep 2022 12:34:17 -0700 Subject: [PATCH 2/3] Add extra metadata to built methods --- src/methodical/impl/combo/threaded.clj | 6 ++++-- src/methodical/impl/multifn/cached.clj | 7 ++++--- src/methodical/impl/multifn/standard.clj | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/methodical/impl/combo/threaded.clj b/src/methodical/impl/combo/threaded.clj index 21cb4e7..2615a9a 100644 --- a/src/methodical/impl/combo/threaded.clj +++ b/src/methodical/impl/combo/threaded.clj @@ -26,7 +26,7 @@ ([threader before-primary-afters] (comp (reducer-fn before-primary-afters) threader)) - ([threader primary-methods {:keys [before after around]}] + ([threader primary-methods {:keys [before after around], :as aux-methods}] (when-let [primary (combo.common/combine-primary-methods primary-methods)] (let [methods (concat before [primary] (reverse after)) threaded-fn (combine-with-threader threader methods) @@ -39,7 +39,9 @@ ([a b c] (threaded-fn a b c)) ([a b c d] (threaded-fn a b c d)) ([a b c d & more] (apply threaded-fn a b c d more))) - (vary-meta assoc :methodical/combined-method? true)) + (vary-meta assoc + :methodical/combined-method? true + :methodical/built-from {:primary primary-methods, :aux aux-methods})) around))))) (defmulti threading-invoker diff --git a/src/methodical/impl/multifn/cached.clj b/src/methodical/impl/multifn/cached.clj index ce839f5..55539fb 100644 --- a/src/methodical/impl/multifn/cached.clj +++ b/src/methodical/impl/multifn/cached.clj @@ -61,10 +61,11 @@ ;; cache for dispatch value. This way we don't end up with a bunch of duplicate methods impls for various ;; dispatch values that have the same effective dispatch value cached-effective-dv-method (.cached-method cache effective-dispatch-value) - method (or cached-effective-dv-method method)] + method (-> (or cached-effective-dv-method method) + (vary-meta assoc :methodical/cached-by dispatch-value))] ;; Make sure the method was cached for the effective dispatch value as well, that way if some less-specific ;; dispatch value comes along with the same effective dispatch value we can use the existing method (when-not cached-effective-dv-method - (i/cache-method! cache effective-dispatch-value method)) - (i/cache-method! cache dispatch-value method) + (i/cache-method! cache effective-dispatch-value (vary-meta method assoc :methodical/cached-for effective-dispatch-value))) + (i/cache-method! cache dispatch-value (vary-meta method assoc :methodical/cached-for dispatch-value)) method)))) diff --git a/src/methodical/impl/multifn/standard.clj b/src/methodical/impl/multifn/standard.clj index a2bb31f..771060f 100644 --- a/src/methodical/impl/multifn/standard.clj +++ b/src/methodical/impl/multifn/standard.clj @@ -93,7 +93,9 @@ (let [primary-methods (i/matching-primary-methods dispatcher method-table dispatch-value) aux-methods (i/matching-aux-methods dispatcher method-table dispatch-value)] (some-> (i/combine-methods method-combination primary-methods aux-methods) - (with-meta {:dispatch-value (effective-dispatch-value dispatcher dispatch-value primary-methods aux-methods)})))) + (with-meta {:dispatch-value (effective-dispatch-value dispatcher dispatch-value primary-methods aux-methods) + :methodical/built-for dispatch-value + :methodical/built-from {:primary primary-methods, :aux aux-methods}})))) (p.types/deftype+ StandardMultiFnImpl [^MethodCombination combo ^Dispatcher dispatcher From 4916dd164063793ea04e155b60b5d6f407e79af3 Mon Sep 17 00:00:00 2001 From: Cam Saul Date: Thu, 1 Sep 2022 20:15:25 -0700 Subject: [PATCH 3/3] Add editorconfig --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c2e9eae --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# http://editorconfig.org/ + +[*] +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 +end_of_line = lf + +[*.clj] +max_line_length = 120 + +[*.{html,css,mustache,js,jsx,ts,tsx,json}] +indent_size = 2 + +[*.{yaml,yml}] +indent_size = 2