Skip to content

Instantly share code, notes, and snippets.

@xli
Created January 9, 2012 02:18
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 xli/1580639 to your computer and use it in GitHub Desktop.
Save xli/1580639 to your computer and use it in GitHub Desktop.
Load a config.yml file to setup global variables
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