mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
1033d12040
--enable-testing.
33 lines
605 B
Ruby
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
|