lib/ezframe/config.rb in ezframe-0.1.1 vs lib/ezframe/config.rb in ezframe-0.2.0

- old
+ new

@@ -1,27 +1,40 @@ module Ezframe class Config class << self attr_accessor :value_h + def init(dir = "./config") + load_files(dir) + end + def load_files(dir) unless @value_h - Dir["#{dir}/*.yml"].each do |file| - load_one_file(file) + load_dir(dir) + rack_env = ENV['RACK_ENV'] + env_dir = "#{dir}/#{rack_env}" + if rack_env && File.directory?(env_dir) + load_dir(env_dir) end end end + def load_dir(dir) + Dir["#{dir}/*.yml"].each do |file| + load_one_file(file) + end + end + def load_one_file(filename) instr = File.open(filename, &:read) if instr.index("\#{") instr = Template.fill_in_text(instr) end begin yaml = YAML.load(instr) rescue - mylog("YAML load error: #{filename}") + Logger.info("YAML load error: #{filename}") return end @value_h ||={} @value_h.update(yaml.recursively_symbolize_keys) if yaml.length>0 end @@ -31,9 +44,13 @@ end def []=(k, v) @value_h||={} @value_h[k]=v + end + + def delete(k) + @value_h.delete(k) if @value_h[k] end def inspect @value_h.inspect end \ No newline at end of file