I am trying to get into Ruby / Rake. I thought it would be a good idea to separate some configuration out of the Rakefile in a file called configuration. This file has the following content:
email="nobody@nowhere.com"
password="somepassword"
proxy_server="someproxy.com:8080"
puts "config loaded"
Then in my Rakefile I load the configuration file by
load 'configuration'
and use the variables defined later on, e.g.:
task :dummy do
sh = "echo #{proxy_server}"
end
But then I get an error stating that the variable is not defined:
rake aborted!
undefined local variable or method `proxy_server' for #<Object:0xb783595c>
How can I access the configuration variables defined in the configuration file?
Visibility: variables from configuration file are not visible in the script that has executed it. You need to establish a common context, for example using global variables (even if globals are evil:-)) like:
and then
But since rake files are Ruby themselves why use a separate configuration file in the first place? If you need to change the config you can as well edit rake file.