From 8e5c756e0d2ed09e4e95280e9c4a2d1203186a5a Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 30 Jun 2018 12:54:36 +0100 Subject: [PATCH] Added volatility. --- project.clj | 1 + src/adl_support/utils.clj | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/project.clj b/project.clj index 71cb7d1..1089feb 100644 --- a/project.clj +++ b/project.clj @@ -4,4 +4,5 @@ :license {:name "MIT License" :url "https://opensource.org/licenses/MIT"} :dependencies [[org.clojure/clojure "1.8.0"] + [org.clojure/math.numeric-tower "0.0.4"] [selmer "1.10.6"]]) diff --git a/src/adl_support/utils.clj b/src/adl_support/utils.clj index 1c3c61f..bf00b19 100644 --- a/src/adl_support/utils.clj +++ b/src/adl_support/utils.clj @@ -1,8 +1,9 @@ (ns ^{:doc "Application Description Language support library - utility functions." :author "Simon Brooke"} adl-support.utils - (:require [clojure.string :as s] + (:require [clojure.math.numeric-tower :refer [expt]] [clojure.pprint :as p] + [clojure.string :as s] [clojure.xml :as x])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -44,12 +45,14 @@ (defn wrap-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 - [width text] - (s/split-lines - (p/cl-format - nil - (str "~{~<~%~1," width ":;~A~> ~}") - (clojure.string/split text #" ")))) + ([width text] + (s/split-lines + (p/cl-format + nil + (str "~{~<~%~1," width ":;~A~> ~}") + (clojure.string/split text #" ")))) + ([text] + (wrap-lines 76 text))) (defn emit-header @@ -450,3 +453,16 @@ (defn type-for-defined [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)))