You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
895 B
37 lines
895 B
class DsAdmin::Storage::Config
|
|
attr_accessor :model
|
|
|
|
def initialize(conf_data)
|
|
@config = conf_data
|
|
end
|
|
|
|
def con(storage)
|
|
@config[storage.config_key][:con]
|
|
end
|
|
|
|
def query(storage)
|
|
@config[storage.config_key][@model.config_key][:query]
|
|
end
|
|
|
|
def map(storage)
|
|
@config[storage.config_key][@model.config_key][:map]
|
|
end
|
|
|
|
##
|
|
# replace special patterns within config strings with data
|
|
# given by the data hash param. These patterns also allow to send
|
|
# a message to the replaces data e.g. for some kind of subtitution.
|
|
#
|
|
def eval_pattern(pattern, data = {})
|
|
scan_exp = /([^#]*)(#\{(:[^}|]+)(\|([^}]*))?\})?/
|
|
|
|
result = String.new
|
|
pattern.scan(scan_exp) do |m|
|
|
key = m[2][1..m[2].length].to_sym if m[2]
|
|
val = eval('"' + data[key] + '".send ' + m[4]) if data[key] && m[4]
|
|
|
|
result += m[0] + (val || "")
|
|
end
|
|
result
|
|
end
|
|
end
|