Class: ICFS::Web::ConfigS3
Overview
Configuration storage implemented in S3
Constant Summary
Constants inherited from Config
Instance Attribute Summary
Attributes inherited from Config
Instance Method Summary collapse
-
#initialize(defaults, s3, bucket, prefix = nil) ⇒ ConfigS3
constructor
New instance.
-
#load(unam) ⇒ Boolean
Load a user configuration.
-
#save ⇒ Object
Save a user configuration.
Methods inherited from Config
Constructor Details
#initialize(defaults, s3, bucket, prefix = nil) ⇒ ConfigS3
New instance
31 32 33 34 35 36 |
# File 'lib/icfs/web/config_s3.rb', line 31 def initialize(defaults, s3, bucket, prefix=nil) super(defaults) @s3 = s3 @bck = bucket @pre = prefix || ''.freeze end |
Instance Method Details
#load(unam) ⇒ Boolean
Load a user configuration
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/icfs/web/config_s3.rb', line 42 def load(unam) Items.validate(unam, 'User/Role/Group name'.freeze, Items::FieldUsergrp) @unam = unam.dup json = @s3.get_object( bucket: @bck, key: _key(unam) ).body.read @data = Items.parse(json, 'Config values'.freeze, Config::ValConfig) return true rescue @data = {} return false end |
#save ⇒ Object
Save a user configuration
57 58 59 60 61 |
# File 'lib/icfs/web/config_s3.rb', line 57 def save() raise(RuntimeError, 'Save requires a user name'.freeze) if !@unam json = Items.generate(@data, 'Config values'.freeze, Config::ValConfig) @s3.put_object( bucket: @bck, key: _key(@unam), body: json ) end |