Skip to content

Instantly share code, notes, and snippets.

@phillmv
Created October 13, 2016 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillmv/6ed3df5df5b71631013a3695bebd46b6 to your computer and use it in GitHub Desktop.
Save phillmv/6ed3df5df5b71631013a3695bebd46b6 to your computer and use it in GitHub Desktop.
rails config
#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
# 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