Method: Gin::Config#load_config
- Defined in:
- lib/gin/config.rb
#load_config(name) ⇒ Object
Load the given config name, or filename.
# Loads @dir/my_config.yml
config.load_config 'my_config'
config['my_config']
#=> data from file
# Loads the given file if it exists.
config.load_config 'path/to/my_config.yml'
config['my_config']
#=> data from file
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gin/config.rb', line 98 def load_config name name = name.to_s if File.file?(name) filepath = name name = File.basename(filepath, ".yml") else filepath = filepath_for(name) end raise Gin::MissingConfig, "No config file at #{filepath}" unless File.file?(filepath) @lock.write_sync do @load_times[name] = Time.now mtime = File.mtime(filepath) return if mtime == @mtimes[name] @mtimes[name] = mtime c = YAML.load_file(filepath) c = (c['default'] || {}).merge(c[@environment] || {}) @data[name] = c end rescue SYNTAX_ERROR @logger.write "[ERROR] Could not parse config `#{filepath}' as YAML" return nil end |