Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #12] Introduce feature flags to make extension of io/Coercions optional #11

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/me/raynes/fs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
(:refer-clojure :exclude [name parents])
(:require [clojure.zip :as zip]
[clojure.java.io :as io]
[clojure.java.shell :as sh])
[clojure.java.shell :as sh]
[me.raynes.fs.feature-flags :as feature-flags])
(:import [java.io File FilenameFilter]
[java.nio.file Files Path LinkOption CopyOption]
[java.nio.file.attribute FileAttribute]))
Expand Down Expand Up @@ -141,10 +142,11 @@
[path]
(predicate isHidden (file path)))

(extend-protocol io/Coercions
Path
(as-file [this] (.toFile this))
(as-url [this] (.. this (toFile) (toURL))))
(when feature-flags/extend-coercions?
(extend-protocol io/Coercions
Path
(as-file [this] (.toFile this))
(as-url [this] (.. this (toFile) (toURL)))))

(defn- ^Path as-path
"Convert `path` to a `java.nio.file.Path`.
Expand Down
12 changes: 12 additions & 0 deletions src/me/raynes/fs/feature_flags.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns me.raynes.fs.feature-flags
"Compile-time feature flags.

In order to use them:

* `require` this ns before any other ns from this lib.
* `alter-var-root` a given feature flag within this ns to a different, desired value
* proceed to `require` the rest of this library.")

(def extend-coercions?
"Should the clojure.java.io/Coercions protocol be extended by this library?"
true)