Created
January 9, 2012 02:18
-
-
Save xli/1580639 to your computer and use it in GitHub Desktop.
Load a config.yml file to setup global variables
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
require 'fileutils' | |
require 'yaml' | |
require 'erb' | |
module PlatformConfig | |
def load(config_yml) | |
unless File.exists?(config_yml) | |
FileUtils.cp("#{config_yml}.example", config_yml) | |
end | |
if platform_config = YAML.load(ERB.new(File.read(config_yml)).result)[RUBY_PLATFORM] | |
puts "Load test config for #{RUBY_PLATFORM} platform from #{config_yml}" | |
platform_config.each do |name, value| | |
eval("$#{name} = #{value.inspect}") | |
end | |
else | |
raise "No platform #{RUBY_PLATFORM} config found in #{config_yml}" | |
end | |
end | |
module_function :load | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment