Ratch  Ratch::ConfigUtils

[Validate]
Generated with Newfish 0.1.0

ConfigUtils

Utility extensions for working with configuration files.

Public Class Methods

extended(base) click to toggle source
    # File lib/ratch/utils/config.rb, line 14
14:     def self.extended(base)
15:       included(base)
16:     end
included(base) click to toggle source
    # File lib/ratch/utils/config.rb, line 10
10:     def self.included(base)
11:       require 'yaml'
12:     end

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.