class Chatterbot::ConfigManager
wrap YAML::Store to maintain config but have a few read-only variables which we will never set/override
Constants
- READ_ONLY_VARIABLES
list of vars that shouldn't ever be written
Attributes
no_update[RW]
if true, we will never actually update the config file
Public Class Methods
new(dest, read_only={}, no_update=false)
click to toggle source
# File lib/chatterbot/config_manager.rb, line 16 def initialize(dest, read_only={}, no_update=false) @read_only = read_only @store = YAML::Store.new(dest, true) @no_update = no_update end
Public Instance Methods
[](key)
click to toggle source
retrieve a key
# File lib/chatterbot/config_manager.rb, line 45 def [](key) if READ_ONLY_VARIABLES.include?(key) && @read_only[key] return @read_only[key] end @store.transaction do @store[key] end end
[]=(key, value)
click to toggle source
set/update a key
# File lib/chatterbot/config_manager.rb, line 37 def []=(key, value) return if @no_update == true @store.transaction do @store[key] = value end end
delete(key)
click to toggle source
delete a key from the config
# File lib/chatterbot/config_manager.rb, line 23 def delete(key) return if @no_update == true @store.transaction do @store.delete(key) end end
to_h()
click to toggle source
# File lib/chatterbot/config_manager.rb, line 30 def to_h @store.transaction do Hash[@store.roots.map { |k| [k, @store[k]] }] end end