1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/report-generators/lib/string-store.rb
2010-07-20 14:38:44 +00:00

33 lines
605 B
Ruby

# Provides a simple way of accessing the contents of files by a symbol
# name. Useful for erb templates.
require 'pathname'
class StringStore
attr_accessor :path
def initialize(p)
@paths = p.nil? ? Array.new : p # FIXME: do we need to copy p ?
end
def lookup(sym)
files = expansions(sym)
@paths.each do |p|
files.each do |f|
pn = Pathname.new("#{p}/#{f}")
if pn.file?
return pn.read
end
end
end
raise RuntimeError, "unknown string entry: #{sym}"
end
private
def expansions(sym)
["#{sym}", "#{sym}.txt"]
end
end