class Redis::Stream::Config
Simple way to read and manage a config.yml file
Public Class Methods
[](key)
click to toggle source
get the value for a key @param [String] key key of key/value @return [Object] value of key/value pair
# File lib/redis/stream/config.rb, line 38 def self.[](key) init @config[key] end
[]=(key, value)
click to toggle source
set a value into the config.yml file @param [String] key @param [Object] value @return [Object]
# File lib/redis/stream/config.rb, line 47 def self.[]=(key, value) init @config[key] = value File.open("#{path}/#{name}", 'w') do |f| f.puts @config.to_yaml end end
include?(key)
click to toggle source
is key available in config store
@param [String] key key to lookup @return [Boolean]
# File lib/redis/stream/config.rb, line 58 def self.include?(key) init @config.include?(key) end
name()
click to toggle source
get name of config file
@return [String] get name of config file
# File lib/redis/stream/config.rb, line 13 def self.name @config_file_name end
name=(config_file_name)
click to toggle source
set config file name defaults to config.yml
@param [String] config_file_name Name of config file
# File lib/redis/stream/config.rb, line 19 def self.name=(config_file_name) @config_file_name = config_file_name end
path()
click to toggle source
return the current location of the config.yml file @return [String] path of config.yml
# File lib/redis/stream/config.rb, line 25 def self.path @config_file_path end
path=(config_file_path)
click to toggle source
set path to config file @param [String] config_file_path path to config.yml file
# File lib/redis/stream/config.rb, line 31 def self.path=(config_file_path) @config_file_path = config_file_path end
Private Class Methods
discover_config_file_path()
click to toggle source
determine location of config.yml file
# File lib/redis/stream/config.rb, line 84 def self.discover_config_file_path if @config_file_path.nil? || @config_file_path.empty? if File.exist?(name) @config_file_path = '.' elsif File.exist?("config/#{name}") @config_file_path = 'config' end end end
file_exists?()
click to toggle source
check if config file is present on system @return [TrueClass, FalseClass]
# File lib/redis/stream/config.rb, line 76 def self.file_exists? discover_config_file_path File.exists?("#{path}/#{name}") end
init()
click to toggle source
load and prepare config.yml
# File lib/redis/stream/config.rb, line 66 def self.init discover_config_file_path if @config.empty? config = YAML::load_file("#{path}/#{name}") @config = process(config) end end
process(config)
click to toggle source
process config.yml file
@param [Object] config yaml data @return [Object]
# File lib/redis/stream/config.rb, line 97 def self.process(config) new_config = {} config.each do |k, v| if config[k].is_a?(Hash) v = process(v) end new_config.store(k.to_sym, v) end new_config end