NIHVIVO-1129 Create the UploadFileFaker, so we can mock up an "uploads" directory based on the data in the model.
This commit is contained in:
parent
73338f1453
commit
2d45d7041b
2 changed files with 266 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
=begin
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
A utility class that reads a properties file and returns a hash containing the
|
||||
properties.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
=end
|
||||
|
||||
class PropertyFileReader
|
||||
# Read a properties file and return a hash.
|
||||
#
|
||||
# Parameters: the path to the properties file
|
||||
#
|
||||
# The hash includes the special property "properties_file_path", which holds
|
||||
# the path to the properties file.
|
||||
#
|
||||
def self.read(file_path)
|
||||
properties = {}
|
||||
properties["properties_file_path"] = File.expand_path(file_path)
|
||||
|
||||
File.open(file_path) do |file|
|
||||
file.each_line do |line|
|
||||
line.strip!
|
||||
if line.length == 0 || line[0] == ?# || line[0] == ?!
|
||||
# ignore blank lines, and lines starting with '#' or '!'.
|
||||
elsif line =~ /(.*?)\s*[=:]\s*(.*)/
|
||||
# key and value are separated by '=' or ':' and optional whitespace.
|
||||
properties[$1.strip] = $2
|
||||
else
|
||||
# No '=' or ':' means that the value is empty.
|
||||
properties[line] = ''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return properties
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue