Skip to content

Commit e7ce904

Browse files
authored
Merge pull request #32 from 200ok-ch/change-runtime-env-from-lumo-to-clojure
Change runtime env from lumo to clojure
2 parents 8495dca + 7259b86 commit e7ce904

33 files changed

+707
-633
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,16 @@
22
.cpcache
33
.classpath
44
.lumo_cache/
5+
/target
6+
/classes
7+
/checkouts
8+
profiles.clj
9+
pom.xml
10+
pom.xml.asc
11+
*.jar
12+
*.class
13+
/.lein-*
14+
/.nrepl-port
15+
/.prepl-port
16+
.hgignore
17+
.hg/

project.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(defproject easy "0.1.0-SNAPSHOT"
2+
:description "FIXME: write description"
3+
:url "http://example.com/FIXME"
4+
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
5+
:url "https://www.eclipse.org/legal/epl-2.0/"}
6+
:dependencies [[org.clojure/clojure "1.11.3"]
7+
[clj-time "0.15.2"]
8+
[org.clojure/data.csv "1.1.0"]
9+
[clj-commons/clj-yaml "1.0.27"]
10+
[hbs "1.0.3"]
11+
[org.clojure/tools.cli "1.1.230"]]
12+
:main ^:skip-aot easy.core
13+
:target-path "target/%s"
14+
:profiles {:uberjar {:aot :all
15+
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}
16+
:dev {:plugins [[lein-binplus "0.6.8"]]}}
17+
:bin {:name "easy"
18+
:bin-path "~/bin"
19+
:jvm-opts ["-server" "-Dfile.encoding=utf-8" "$JVM_OPTS" ]})
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
(ns easy.collect
2-
(:require [lumo.util :as lumo]
3-
[easy.util :as util]
2+
(:require [easy.util :as util]
43
[easy.log :as log]
54
[clojure.tools.cli :refer [parse-opts]]
6-
[cljs.pprint :refer [pprint]]
7-
[cljs.spec.alpha :as s]
5+
[clojure.pprint :refer [pprint]]
6+
[clojure.spec.alpha :as s]
87
[clojure.string :refer [join]]))
98

10-
119
(def cli-options
1210
[;; ["-d" "--debug" "Debug output"]
1311
])
1412

15-
1613
(defn- read-and-parse
1714
"Reads & parses YAML files (incl. applying any frontmatter event
1815
templates & source annotation)."
@@ -22,18 +19,15 @@
2219
util/parse-yaml
2320
(util/annotate path)))
2421

25-
2622
(defn- harmonize [events]
2723
(map (partial util/harmonize-date-field :date) events))
2824

29-
30-
(defn -main
31-
[& args]
25+
(defn -main [& args]
3226
(let [cli (parse-opts args cli-options)
3327
path (or (-> cli :arguments first) ".")
3428
options (-> cli :options)]
3529
(->> path
36-
lumo/file-seq
30+
util/file-seq
3731
(filter #(re-matches #"[^.].*\.yml$" %))
3832
(map read-and-parse)
3933
(apply concat)
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
(ns easy.common
22
"This namespace covers the common requirements for all events."
3-
(:require [cljs.spec.alpha :as s]
3+
(:require [clojure.spec.alpha :as s]
44
[easy.util :as util :refer [assoc*]]
5-
[cljs-time.core :as cljs-time]
6-
[cljs-time.format :as time]))
7-
8-
9-
;; spec
5+
[clj-time.core :as time]
6+
[clj-time.coerce :as coerce]
7+
[clj-time.format :as format]))
108

9+
;;; spec
1110

1211
(def match-iso-date (partial re-matches #"^\d{4}-\d\d-\d\d$"))
1312
(def match-template (partial re-matches #".*\.hbs"))
@@ -26,7 +25,8 @@
2625
"salary" ;; Gehalt
2726
"outlay" ;; Spesenabrechnung
2827
"redistribution" ;; "200ok Sozialfaktor"
29-
"dctd"}) ;; Diner's Club Transaction Details
28+
"dctd" ;; Diner's Club Transaction Details
29+
"pfcc"}) ;; Postfinance Credit Cards
3030

3131
(s/def ::date (s/or :date util/date?
3232
:iso-string (s/and string? match-iso-date)))
@@ -39,37 +39,29 @@
3939
::file]))
4040
(s/def ::events (s/coll-of ::event))
4141

42-
43-
;; helpers
44-
42+
;;; helpers
4543

4644
(defn ignore-warning?
4745
"Checks if `evt` has `:ignore-warnings` set for `key`."
4846
[evt key]
4947
(->> (get evt :ignore-warnings [])
5048
(util/include? (name key))))
5149

52-
5350
(defn harmonize [evt]
5451
(->> evt
5552
(util/harmonize-date-field :date)
5653
;; TODO: remove, we don' use `:settled` anymore
5754
(util/harmonize-date-field :settled)))
5855

59-
6056
(defn validate!
6157
"Same as `util/validate!`, but with arguments swapped."
6258
[x spec]
6359
(util/validate! spec x))
6460

65-
6661
(defn make-iso-date [date]
67-
(->> date
68-
cljs-time/date-time
69-
(time/unparse util/iso-formatter)))
70-
62+
(format/unparse util/iso-formatter date))
7163

72-
;; transformers
64+
;;; transformers
7365

7466
(defn add-iso-date
7567
"Transformer that takes the value of `:date`, builds an iso-date
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
(ns easy.common.invoice-no
22
(:require [clojure.string :as str]
3-
[cljs.spec.alpha :as s]
3+
[clojure.spec.alpha :as s]
44
[easy.util :as util]))
55

6-
7-
;; spec
8-
6+
;;; spec
97

108
(def match-invoice-no (partial re-matches #"^\d+\.\d+\.\d+$"))
119

@@ -20,9 +18,7 @@
2018
::number
2119
::version])))
2220

23-
24-
;; transformers
25-
21+
;;; transformers
2622

2723
(defn- add-invoice-no
2824
"Compile `invoice-no` from invoice details like `customer-id`,
@@ -33,19 +29,17 @@
3329
(str/join ".")
3430
(util/assoc* evt :invoice-no)))
3531

36-
3732
(defn- add-invoice-no-details
3833
"Derive invoice details like `customer-id`, `number` and `version`
3934
from `invoice-no`, if given."
4035
[{:keys [invoice-no] :as evt}]
4136
(if invoice-no
4237
(->> (str/split invoice-no #"\.")
43-
(map int)
38+
(map util/parse-int)
4439
(zipmap [:customer-id :number :version])
4540
(util/merge* evt))
4641
evt))
4742

48-
4943
(def unify
5044
"Transform fn for events that attempts to provide both: a compiled
5145
`invoice-no` and invoice details like `customer-id`, `number` and
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
(ns easy.common.tax
2-
(:require [cljs.spec.alpha :as s]
2+
(:require [clojure.spec.alpha :as s]
33
[easy.config :refer [config]]
44
[easy.util :as util :refer [assoc*]]
55
[easy.log :as log]
6-
[easy.common :as common]))
7-
6+
[easy.common :as common]
7+
[clj-time.core :as time]))
88

99
;; specs
1010

11-
12-
(s/def ::rate (s/and float? #(< 0 %) #(> 1 %)))
11+
(s/def ::rate (s/and number? #(< 0 %) #(> 1 %)))
1312
(s/def ::since util/date?)
1413
(s/def ::until util/date?)
1514

@@ -19,10 +18,8 @@
1918

2019
(s/def ::rates (s/coll-of ::rate-entry :kind vector?))
2120

22-
2321
;; helpers
2422

25-
2623
(defn- assert-exactly-one [coll]
2724
(case (count coll)
2825
;; non found -> abort
@@ -36,28 +33,25 @@
3633
"Just picked the first from " coll))
3734
(first coll))))
3835

39-
4036
(defn lookup-rate
4137
[key {:keys [date]}]
4238
(->> @config
4339
key
4440
;; TODO: use `(common/validate! ::rates)` here
45-
(filter #(or (nil? (:since %)) (>= date (:since %))))
46-
(filter #(or (nil? (:until %)) (<= date (:until %))))
41+
(filter #(or (nil? (:since %)) (not (time/before? date (:since %)))))
42+
(filter #(or (nil? (:until %)) (not (time/after? date (:until %)))))
4743
assert-exactly-one
4844
:rate))
4945

50-
5146
;; transformers
5247

53-
5448
(defn add-period
5549
"The period is when the vat is due."
5650
([evt] (add-period evt [:date]))
5751
([evt date-path]
5852
(if-let [date (get-in evt date-path)]
59-
(let [year (.getFullYear date)
60-
semester (if (< (.getMonth date) 6) 1 2)
53+
(let [year (time/year date)
54+
semester (if (< (time/month date) 6) 1 2)
6155
period (str year "-H" semester)]
6256
(assoc* evt :period period))
6357
;; no date found, in context of a nested transform, that's ok
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
(ns easy.config
22
(:require [easy.util :as util]))
33

4-
54
;; TODO: `config` should probably instead be named `environment`
65

7-
86
(def default-config
97
"The easy config file is a YAML file with the following structure, e.g.
108
```
@@ -48,13 +46,14 @@
4846
:report
4947
{:template "templates/report.txt.hbs"}}})
5048

51-
5249
(def config (atom default-config))
5350

51+
(defn load-config-file []
52+
(if (util/file-exists? ".easy.yml")
53+
(util/parse-yaml (slurp ".easy.yml"))
54+
{}))
5455

5556
(defn load! []
56-
;; TODO: check if file exists, otherwise print a helpful error
57-
;; message
58-
(->> (util/slurp ".easy.yml")
59-
util/parse-yaml
60-
(swap! config util/deep-merge)))
57+
(swap! config
58+
util/deep-merge
59+
(load-config-file)))

0 commit comments

Comments
 (0)