lib/spiderfw/config/configuration.rb in spiderfw-0.5.7 vs lib/spiderfw/config/configuration.rb in spiderfw-0.5.9
- old
+ new
@@ -148,10 +148,30 @@
yield key, val
end
end
end
+ def options
+ options = []
+ def iterate_options(src, prefix, dst)
+ src.each do |key, val|
+ full_key = prefix ? "#{prefix}.#{key}" : key
+ if val[:params]
+ if val[:params][:type] == :conf
+ iterate_options(src[key]["x"], full_key+'.x', dst)
+ else
+ dst << full_key
+ end
+ else
+ iterate_options(src[key], full_key, dst)
+ end
+ end
+ end
+ iterate_options(@options, nil, options)
+ options
+ end
+
# Sets an allowed configuration option
# Possible params are:
# -:default the default value for the option; if it is a proc, it will be called
# -:choiches an array of allowed values
# -:type parameter type; can be one of int, string, bool
@@ -167,9 +187,19 @@
while (rest)
o = (o[first] ||= {})
first, rest = rest.split('.', 2)
end
o[first] = {:description => description, :params => params}
+ end
+
+ def option(name)
+ o = @options
+ first, rest = name.split('.', 2)
+ while (rest)
+ o = (o[first] ||= {})
+ first, rest = rest.split('.', 2)
+ end
+ return o[first]
end
def get(key)
\ No newline at end of file