Added volatility.
This commit is contained in:
parent
701fc1a21d
commit
8e5c756e0d
|
@ -4,4 +4,5 @@
|
||||||
:license {:name "MIT License"
|
:license {:name "MIT License"
|
||||||
:url "https://opensource.org/licenses/MIT"}
|
:url "https://opensource.org/licenses/MIT"}
|
||||||
:dependencies [[org.clojure/clojure "1.8.0"]
|
:dependencies [[org.clojure/clojure "1.8.0"]
|
||||||
|
[org.clojure/math.numeric-tower "0.0.4"]
|
||||||
[selmer "1.10.6"]])
|
[selmer "1.10.6"]])
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
(ns ^{:doc "Application Description Language support library - utility functions."
|
(ns ^{:doc "Application Description Language support library - utility functions."
|
||||||
:author "Simon Brooke"}
|
:author "Simon Brooke"}
|
||||||
adl-support.utils
|
adl-support.utils
|
||||||
(:require [clojure.string :as s]
|
(:require [clojure.math.numeric-tower :refer [expt]]
|
||||||
[clojure.pprint :as p]
|
[clojure.pprint :as p]
|
||||||
|
[clojure.string :as s]
|
||||||
[clojure.xml :as x]))
|
[clojure.xml :as x]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -44,12 +45,14 @@
|
||||||
(defn wrap-lines
|
(defn wrap-lines
|
||||||
"Wrap lines in this `text` to this `width`; return a list of lines."
|
"Wrap lines in this `text` to this `width`; return a list of lines."
|
||||||
;; Shamelessly adapted from https://www.rosettacode.org/wiki/Word_wrap#Clojure
|
;; Shamelessly adapted from https://www.rosettacode.org/wiki/Word_wrap#Clojure
|
||||||
[width text]
|
([width text]
|
||||||
(s/split-lines
|
(s/split-lines
|
||||||
(p/cl-format
|
(p/cl-format
|
||||||
nil
|
nil
|
||||||
(str "~{~<~%~1," width ":;~A~> ~}")
|
(str "~{~<~%~1," width ":;~A~> ~}")
|
||||||
(clojure.string/split text #" "))))
|
(clojure.string/split text #" "))))
|
||||||
|
([text]
|
||||||
|
(wrap-lines 76 text)))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-header
|
(defn emit-header
|
||||||
|
@ -450,3 +453,16 @@
|
||||||
(defn type-for-defined
|
(defn type-for-defined
|
||||||
[property application]
|
[property application]
|
||||||
(:type (:attrs (typedef property application))))
|
(:type (:attrs (typedef property application))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn volatility
|
||||||
|
"Return the cache ttl in seconds for records of this `entity`."
|
||||||
|
[entity]
|
||||||
|
(try
|
||||||
|
(let
|
||||||
|
[v (read-string (:volatility (:attrs entity)))]
|
||||||
|
(if
|
||||||
|
(zero? v)
|
||||||
|
0
|
||||||
|
(expt 10 v)))
|
||||||
|
(catch Exception _ 0)))
|
||||||
|
|
Loading…
Reference in a new issue