Configuration information is often stored in a text file. When using Rake the information can be put into a yaml file that is highly readable and maintainable without all the unnecessary noise.
--- !ruby/object:ConfigurationNext, you will need to create a Configuration class.
catalog: cat
data_source: source
password: password
user: jay
Yaml.rb::load
will automatically load your configuration information into an instance of the Configuration class.class ConfigurationAt this point you are ready to access your configuration information via methods of the object. The following test verifies the expected behavior.
attr_accessor :user, :password, :data_source, :catalog
end
require 'yaml'*SciTE formatting
require 'test/unit'
class TestConfiguration < Test::Unit::TestCase
def testYmlLoaded
config = YAML::load(File.open('config.yaml'))
assert_equal("jay",config.user)
assert_equal("password",config.password)
assert_equal("source",config.data_source)
assert_equal("cat",config.catalog)
end
end
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.