Created
October 24, 2011 14:54
-
-
Save lenny/1309229 to your computer and use it in GitHub Desktop.
Ruby wrapper around Java Properties
This file contains hidden or 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
# More rubyish/convenient interface to Java Properties(e.g. Loading connection config from properties file) | |
class JavaProperties | |
def initialize(name) | |
input_stream = | |
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(name) | |
if input_stream | |
@properties = Java::java.util.Properties.new | |
@properties.load(input_stream) | |
input_stream.close | |
else | |
raise "#{name} not found in classpath" | |
end | |
end | |
def [](name) | |
@properties.getProperty(name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment