Class: ICFS::Web::ConfigRedis
- Defined in:
- lib/icfs/web/config_redis.rb
Overview
Implement Config with a Redis cache
Constant Summary
Constants inherited from Config
Instance Attribute Summary
Attributes inherited from Config
Instance Method Summary collapse
-
#initialize(redis, base, opts = {}) ⇒ ConfigRedis
constructor
New instance.
-
#load(unam) ⇒ Boolean
Load a user configuration.
-
#save ⇒ Object
Save a user configuration.
Methods inherited from Config
Constructor Details
#initialize(redis, base, opts = {}) ⇒ ConfigRedis
New instance
32 33 34 35 36 37 38 |
# File 'lib/icfs/web/config_redis.rb', line 32 def initialize(redis, base, opts={}) super(base.defaults) @redis = redis @base = base @pre = opts[:prefix] || ''.freeze @exp = opts[:expires] || 1*60*60 # 1 hour default end |
Instance Method Details
#load(unam) ⇒ Boolean
Load a user configuration
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/icfs/web/config_redis.rb', line 44 def load(unam) Items.validate(unam, 'User/Role/Group name'.freeze, Items::FieldUsergrp) @unam = unam.dup key = _key(unam) # try cache json = @redis.get(key) if json @data = Items.parse(json, 'Config values'.freeze, Config::ValConfig) return true end # get base object succ = @base.load(unam) @data = @base.data return succ end |
#save ⇒ Object
Save a user configuration
66 67 68 69 70 71 72 |
# File 'lib/icfs/web/config_redis.rb', line 66 def save() raise(RuntimeError, 'Save requires a user name'.freeze) if !@unam json = Items.generate(@data, 'Config values'.freeze, Config::ValConfig) @redis.del(_key(@unam)) @base.data = @data @base.save end |