-
Notifications
You must be signed in to change notification settings - Fork 11
/
types.clj
31 lines (27 loc) · 968 Bytes
/
types.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns lambdaisland.cucumber.jvm.types
(:import [java.io File InputStream FileInputStream]
[java.util Iterator]
[java.lang Iterable]
[cucumber.runtime.io Resource ResourceLoader])
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(defn file-resource ^Resource [^File root ^File file]
(reify
Resource
(getPath ^String [_]
(.getPath file))
(getInputStream ^InputStream [_]
(FileInputStream. file))
Object
(toString [_]
(str "<file-resource: @root=" root ", @file=" file ">"))))
(defn file-resource-seq ^Iterator [root suffix]
(->> (io/file root)
file-seq
(filter (fn [^File f]
(and (.isFile f) (str/ends-with? (str f) suffix))))
(map #(file-resource root %))))
(defn file-resource-loader ^ResourceLoader []
(reify ResourceLoader
(^Iterable resources [_ ^String path ^String suffix]
(file-resource-seq path suffix))))