11# frozen_string_literal: true
22
3+ require "class_composer"
4+ require "json_schematize/errors"
5+
36module JsonSchematize
47 class Configuration
8+ include ClassComposer ::Generator
9+
510 DEFAULT_ONE_MIN = 60 * 60
611 DEFAULT_ONE_HOUR = DEFAULT_ONE_MIN * 60
712 DEFAULT_ONE_DAY = DEFAULT_ONE_HOUR * 24
@@ -14,16 +19,11 @@ class Configuration
1419 cache_update_on_change : true ,
1520 }
1621
17- attr_accessor *DEFAULT_CACHE_OPTIONS . keys
18-
19- def initialize
20- @cache_client = DEFAULT_CACHE_OPTIONS [ :cache_client ]
21- @cache_key = DEFAULT_CACHE_OPTIONS [ :cache_key ]
22- @cache_namespace = DEFAULT_CACHE_OPTIONS [ :cache_namespace ]
23- @cache_stochastic_bust = DEFAULT_CACHE_OPTIONS [ :cache_stochastic_bust ]
24- @cache_ttl = DEFAULT_CACHE_OPTIONS [ :cache_ttl ]
25- @cache_update_on_change = DEFAULT_CACHE_OPTIONS [ :cache_update_on_change ]
26- end
22+ add_composer :cache_key , allowed : Proc , default : DEFAULT_CACHE_OPTIONS [ :cache_key ] , validation_error_klass : ::JsonSchematize ::ConfigError , invalid_message : -> ( val ) { _assign_msg_ ( "cache_key" , "->(val, cusom_key) { val.hash }" , "Default proc to assign cache key" ) }
23+ add_composer :cache_namespace , allowed : [ String , Symbol ]
24+ add_composer :cache_stochastic_bust , allowed : [ Float , Integer ] , default : DEFAULT_CACHE_OPTIONS [ :cache_stochastic_bust ]
25+ add_composer :cache_ttl , allowed : [ Float , Integer ] , default : DEFAULT_CACHE_OPTIONS [ :cache_ttl ]
26+ add_composer :cache_update_on_change , allowed : [ TrueClass , FalseClass ] , default : DEFAULT_CACHE_OPTIONS [ :cache_update_on_change ]
2727
2828 def cache_hash
2929 DEFAULT_CACHE_OPTIONS . map do |key , value |
0 commit comments