lib/redis/stream/config.rb in redis-stream-0.2.0 vs lib/redis/stream/config.rb in redis-stream-0.3.0
- old
+ new
@@ -4,11 +4,24 @@
module Stream
# Simple way to read and manage a config.yml file
class Config
@config = {}
@config_file_path = ""
+ @config_file_name = 'config.yml'
+ #get name of config file
+ # @return [String] get name of config file
+ def self.name
+ @config_file_name
+ end
+
+ #set config file name defaults to config.yml
+ # @param [String] config_file_name Name of config file
+ def self.name=(config_file_name)
+ @config_file_name = config_file_name
+ end
+
# return the current location of the config.yml file
# @return [String] path of config.yml
def self.path
@config_file_path
end
@@ -32,11 +45,11 @@
# @param [Object] value
# @return [Object]
def self.[]=(key, value)
init
@config[key] = value
- File.open("#{path}/config.yml", 'w') do |f|
+ File.open("#{path}/#{name}", 'w') do |f|
f.puts @config.to_yaml
end
end
#is key available in config store
@@ -51,22 +64,29 @@
# load and prepare config.yml
def self.init
discover_config_file_path
if @config.empty?
- config = YAML::load_file("#{path}/config.yml")
+ config = YAML::load_file("#{path}/#{name}")
@config = process(config)
end
end
+ # check if config file is present on system
+ # @return [TrueClass, FalseClass]
+ def self.file_exists?
+ discover_config_file_path
+ File.exists?("#{path}/#{name}")
+ end
+
private
#determine location of config.yml file
def self.discover_config_file_path
if @config_file_path.nil? || @config_file_path.empty?
- if File.exist?('config.yml')
+ if File.exist?(name)
@config_file_path = '.'
- elsif File.exist?("config/config.yml")
+ elsif File.exist?("config/#{name}")
@config_file_path = 'config'
end
end
end
\ No newline at end of file