make source type configurable

This commit is contained in:
jem 2020-02-07 20:22:53 +01:00
parent b6d1b9adcd
commit 24b55040f0
2 changed files with 38 additions and 30 deletions

View file

@ -35,21 +35,23 @@
(defn create-resource
([virtual-path
java-path]
java-path
source-type]
(if (nil? java-path)
nil
{:virtual-path virtual-path
:java-uri (.toUri java-path)
:java-path java-path
:source-type :filesystem
:source-type source-type
:resource-type (cond
(Files/isDirectory java-path follow-link-option) :dir
(Files/isRegularFile java-path follow-link-option) :file
:else :unknown)}))
([fs-prefix
base-path
virtual-path]
(create-resource virtual-path (path-if-exists fs-prefix base-path virtual-path))))
virtual-path
source-type]
(create-resource virtual-path (path-if-exists fs-prefix base-path virtual-path) source-type)))
(defn
list-entries-for-dir
@ -57,10 +59,10 @@
(.list (.toFile (:java-path resource))))
(defn get-resources ;:- [Resource]
[fs-prefix ;:- Prefix
([fs-prefix ;:- Prefix
base-path ;:- VirtualPath
paths ;:- [VirtualPath]
]
source-type]
(loop [paths paths
result []]
(if (not (empty? paths))
@ -68,7 +70,8 @@
resource-to-work-with (create-resource
fs-prefix
base-path
path-to-work-with)
path-to-work-with
source-type)
result (into result
[resource-to-work-with])]
(cond
@ -82,3 +85,8 @@
result)
:else []))
(remove nil? result))))
([fs-prefix ;:- Prefix
base-path ;:- VirtualPath
paths ;:- [VirtualPath]
]
(get-resources fs-prefix base-path paths :filesystem)))

View file

@ -35,7 +35,7 @@
(= ["dummy2" "dummy_from_fs"]
(seq
(sut/list-entries-for-dir
(sut/create-resource "dummy" (sut/path-if-exists fs-root "dummy")))))))
(sut/create-resource "dummy" (sut/path-if-exists fs-root "dummy") :filesytem))))))
(deftest test-get-resources
(is