Included Modules

Files

RConfig::Utils

Public Instance Methods

app_root() click to toggle source
    # File lib/rconfig/utils.rb, line 53
53:     def app_root
54:       File.expand_path(File.dirname(__FILE__))
55:     end
create_dottable_hash(hash) click to toggle source

Creates a dottable hash for all Hash objects, recursively.

    # File lib/rconfig/utils.rb, line 72
72:     def create_dottable_hash(hash)
73:       make_indifferent(hash)
74:     end
default_load_paths() click to toggle source

Checks environment for default configuration load paths. Adds them to load paths if found.

    # File lib/rconfig/utils.rb, line 28
28:     def default_load_paths
29:       paths = []
30: 
31:       # Check for Rails config path
32:       paths << "#{::Rails.root}/config" if rails?
33: 
34:       # Check for defined constants
35:       paths << CONFIG_ROOT if defined?(CONFIG_ROOT) && Dir.exists?(CONFIG_ROOT)
36:       paths << CONFIG_PATH if defined?(CONFIG_PATH) && Dir.exists?(CONFIG_PATH)
37: 
38:       # Check for config directory in app root
39:       config_dir = File.join(app_root, 'config')
40:       paths << config_dir if Dir.exists?(config_dir)
41: 
42:       paths
43:     end
filename_for_name(name, directory=self.load_paths.first, ext=:yml) click to toggle source

Get complete file name, including file path for the given config name and directory.

     # File lib/rconfig/utils.rb, line 168
168:     def filename_for_name(name, directory=self.load_paths.first, ext=:yml)
169:       File.join(directory, "#{name}.#{ext}")
170:     end
flush_cache(name=nil) click to toggle source

If a config file name is specified, flushes cached config values for specified config file. Otherwise, flushes all cached config data. The latter should be avoided in production environments, if possible.

     # File lib/rconfig/utils.rb, line 150
150:     def flush_cache(name=nil)
151:       if name
152:         name = name.to_s
153:         self.cache_hash[name] &&= nil
154:       else
155:         logger.warn "RConfig: Flushing config data cache."
156:         self.suffixes        = {}
157:         self.cache           = {}
158:         self.cache_files     = {}
159:         self.cache_hash      = {}
160:         self.last_auto_check = {}
161:         self
162:       end
163:     end
log_level() click to toggle source
    # File lib/rconfig/utils.rb, line 66
66:     def log_level
67:       logger.try(:level)
68:     end
log_level=(level) click to toggle source

Helper method for white-box testing and debugging. Sets the flag indicating whether or not to log errors and application run-time information.

    # File lib/rconfig/utils.rb, line 61
61:     def log_level=(level)
62:       return unless logger
63:       logger.level = level unless level.nil?
64:     end
make_indifferent(hash) click to toggle source

Recursively makes hashes into frozen IndifferentAccess Config Hash Arrays are also traversed and frozen.

     # File lib/rconfig/utils.rb, line 122
122:     def make_indifferent(hash)
123:       case hash
124:         when Hash
125:           unless hash.frozen?
126:             hash.each do |k, v|
127:               hash[k] = make_indifferent(v)
128:             end
129:             hash = RConfig::Config.new.merge!(hash).freeze
130:           end
131:           logger.debug "make_indefferent: x = #{hash.inspect}:#{hash.class}"
132:         when Array
133:           unless hash.frozen?
134:             hash.collect! do |v|
135:               make_indifferent(v)
136:             end
137:             hash.freeze
138:           end
139:           # Freeze Strings.
140:         when String
141:           hash.freeze
142:         end
143:       hash
144:     end
merge_hashes(hashes) click to toggle source

Returns a merge of hashes.

     # File lib/rconfig/utils.rb, line 114
114:     def merge_hashes(hashes)
115:       hashes.inject({}) { |n, h| n.weave(h, true) }
116:     end
parse(contents, name, ext) click to toggle source

Parses contents of the config file based on file type. XML files expect the root element to be the same as the file name.

     # File lib/rconfig/utils.rb, line 89
 89:     def parse(contents, name, ext)
 90:       hash = case ext
 91:         when *YML_FILE_TYPES
 92:           YAML::load(contents)
 93:         when *XML_FILE_TYPES
 94:           parse_xml(contents, name)
 95:         when *CNF_FILE_TYPES
 96:           RConfig::PropertiesFile.parse(contents)
 97:         else
 98:           raise ConfigError, "Unknown File type: #{ext}"
 99:         end
100:       hash.freeze
101:     end
parse_xml(contents, name) click to toggle source

Parses xml file and processes any references in the property values.

     # File lib/rconfig/utils.rb, line 105
105:     def parse_xml(contents, name)
106:       hash = Hash.from_xml(contents)
107:       hash = hash[name] if hash.size == 1 && hash.key?(name)  # xml document could have root tag matching the file name.
108:       RConfig::PropertiesFile.parse_references(hash)
109:     end
rails?() click to toggle source

Returns true if the current application is a rails app.

    # File lib/rconfig/utils.rb, line 47
47:     def rails?
48:       !!defined?(::Rails)
49:     end
read(file, name, ext) click to toggle source

Reads and parses the config data from the specified file.

    # File lib/rconfig/utils.rb, line 78
78:     def read(file, name, ext)
79:       contents = File.read(file)           # Read the contents from the file.
80:       contents = ERB.new(contents).result  # Evaluate any ruby code using ERB.
81:       parse(contents, name, ext)           # Parse the contents based on the file type
82:     end
setting(name, default=nil) click to toggle source

Creates a class variable a sets it to the default value specified.

    # File lib/rconfig/utils.rb, line 14
14:     def setting(name, default=nil)
15:       RConfig.class_eval         def self.#{name}          @@#{name}        end        def self.#{name}=(val)          @@#{name} = val        end, __FILE__, __LINE__ + 1
16: 
17:       RConfig.send(:"#{name}=", default)
18:     end
setup() click to toggle source

Used to customize configuration of RConfig. Run ‘rails generate rconfig:install’ to create a fresh initializer with all configuration values.

    # File lib/rconfig/utils.rb, line 7
 7:     def setup
 8:       yield self
 9:       raise_load_path_error if load_paths.empty?
10:       self.logger ||= DisabledLogger.new
11:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.