class ServantConfigDb
Public Class Methods
new(json_string)
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 11 def initialize(json_string) @config = JSON.parse(json_string) # validation: @config is a hash, keys are strings, vals are strings if (@config.class != {}.class) raise ServantConfigException, "ServantConfig error: JSON string did not evaluate to an object", caller end @config.each{|key, value| if (value.class != "".class) raise ServantConfigException, ("ServantConfig error: JSON initialization string, "+ "value for key '#{key}' is type '#{value.class}'"), caller end } @config.default "" @readonly = [] end
Public Instance Methods
get(key)
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 35 def get(key) @config[key] end
is_readonly(key)
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 50 def is_readonly(key) @readonly.include? key end
set(key, value)
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 39 def set(key, value) key = key.to_s value = value.to_s if @readonly.include? key raise ServantConfigException, "Attempted to change read-only property '#{key}'", caller end @config[key]=value end
set_readonly(key)
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 54 def set_readonly(key) @readonly << key end
to_json()
click to toggle source
# File lib/belphanior/servant/servant_config_db.rb, line 31 def to_json JSON.dump(@config) end