|
16 | 16 |
|
17 | 17 | (def jq-version Versions/JQ_1_6)
|
18 | 18 |
|
| 19 | +(defn ->JsonNode ^JsonNode [data] |
| 20 | + (if (instance? JsonNode data) |
| 21 | + data |
| 22 | + (.valueToTree mapper data))) |
| 23 | + |
19 | 24 | (defn ->absolute-path
|
20 | 25 | "FileSystemModuleLoader requires absolute paths."
|
21 | 26 | ^Path [^String file-path]
|
|
50 | 55 | (.loadFunctions (BuiltinFunctionLoader/getInstance) jq-version scope)
|
51 | 56 | scope))
|
52 | 57 |
|
53 |
| -(defn new-scope |
54 |
| - (^Scope [] (Scope/newChildScope root-scope)) |
55 |
| - (^Scope [opts] |
56 |
| - (let [^Scope scope (new-scope) |
57 |
| - module-paths (get opts :modules) |
58 |
| - module-paths (if (string? module-paths) [module-paths] module-paths)] |
59 |
| - (when (seq module-paths) |
60 |
| - (setup-modules! scope module-paths)) |
61 |
| - scope))) |
62 |
| - |
63 | 58 | ; Helper interface that specifies a method to get a string value.
|
64 | 59 | (definterface IContainer
|
65 | 60 | ; net.thisptr.jackson.jq/Output
|
|
115 | 110 | ^String [^JsonNode data ^JsonQuery query ^Scope scope ^IContainer output-container]
|
116 | 111 | (json-node->string (apply-json-query-on-json-node data query scope output-container)))
|
117 | 112 |
|
| 113 | +(defn new-scope |
| 114 | + (^Scope [] (Scope/newChildScope root-scope)) |
| 115 | + (^Scope [opts] |
| 116 | + (let [^Scope scope (new-scope) |
| 117 | + module-paths (get opts :modules) |
| 118 | + module-paths (if (string? module-paths) [module-paths] module-paths) |
| 119 | + variables (get opts :vars)] |
| 120 | + (when (seq module-paths) |
| 121 | + (setup-modules! scope module-paths)) |
| 122 | + (when variables |
| 123 | + (doseq [[key value] variables] |
| 124 | + (.setValue scope (name key) (->JsonNode value)))) |
| 125 | + scope))) |
| 126 | + |
118 | 127 | (defn compile-query
|
119 | 128 | "Compiles a JQ query string into a JsonQuery object."
|
120 | 129 | ^JsonQuery [^String query]
|
|
0 commit comments