Created
October 13, 2016 01:31
-
-
Save phillmv/6ed3df5df5b71631013a3695bebd46b6 to your computer and use it in GitHub Desktop.
rails config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#place in config/initializers/ | |
require 'find' | |
settings_path = File.join(Rails.root, "config/settings") | |
search_dirs = [settings_path] | |
files = [] | |
until search_dirs.empty? | |
search_path = search_dirs.shift | |
Find.find(search_path) do |path| | |
unless path == search_path | |
if File.directory?( path ) | |
if File.symlink?(path) | |
search_dirs << "#{path}/" | |
else | |
search_dirs << path | |
end | |
else | |
files << path | |
end | |
end | |
end | |
end | |
files.each do |file| | |
new_conf = YAML.load_file(file) | |
file_name = File.basename(file) | |
next unless new_conf.is_a? Hash | |
if new_conf[Rails.env] | |
new_settings = new_conf[Rails.env] | |
key = new_settings.keys.first | |
if key | |
Rails.configuration.send("#{key}=", OpenStruct.new(new_settings[key])) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/settings/is_it_vuln.yml | |
development: | |
is_it_vuln: | |
domains: | |
- isitvuln.dev | |
# becomes | |
Rails.configuration.isitvuln.domains |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment