In Files
Information
Class Index
- Ratch
- Ratch::Batch
- Ratch::CLI
- Ratch::ConfigUtils
- Ratch::Console
- Ratch::EmailUtils
- Ratch::Emailer
- Ratch::FTPUtils
- Ratch::FileList
- Ratch::FileNotFound
- Ratch::Help
- Ratch::POMUtils
- Ratch::RDocUtils
- Ratch::Script
- Ratch::Shell
- Ratch::System
- Ratch::TarUtils
- Ratch::XDGUtils
- Ratch::ZlibUtils
- FileTest
- Hash
- NilClass
- Object
- String
ConfigUtils
Utility extensions for working with configuration files.
Public Class Methods
Public Instance Methods
configuration(file)
click to toggle source
Load configuration data from a file. Results are cached and an empty Hash is returned if the file is not found.
Since they are YAML files, they can optionally end with ’.yaml’ or ’.yml’.
# File lib/ratch/utils/config.rb, line 22 22: def configuration(file) 23: @configuration ||= {} 24: @configuration[file] ||= ( 25: begin 26: configuration!(file) 27: rescue LoadError 28: Hash.new{ |h,k| h[k] = {} } 29: end 30: ) 31: end
configuration!(file)
click to toggle source
Load configuration data from a file. The “bang” version will raise an error if file is not found. It also does not cache the results.
Since they are YAML files, they can optionally end with ’.yaml’ or ’.yml’.
# File lib/ratch/utils/config.rb, line 37 37: def configuration!(file) 38: @configuration ||= {} 39: patt = file + "{.yml,.yaml,}" 40: path = Dir.glob(patt, File::FNM_CASEFOLD).find{ |f| File.file?(f) } 41: if path 42: # The || {} is in case the file is empty. 43: data = YAML::load(File.open(path)) || {} 44: @configuration[file] = data 45: else 46: raise LoadError, "Missing file -- #{path}" 47: end 48: end
Disabled; run with --debug to generate this.