Commit 4eb7b7fe authored by Antonio Terceiro's avatar Antonio Terceiro

Debci::Config: replace conditionals with hash lookup

parent 47c0f37c
...@@ -43,17 +43,29 @@ module Debci ...@@ -43,17 +43,29 @@ module Debci
end end
end end
def self.types
@types ||= {
/_list$/ => lambda { |x| x.split}, # Array
'quiet' => lambda { |x| x == 'true' }, # boolean
}
end
def self.cast_for(key)
pair = types.find { |k,v| k === key }
if pair
pair[1]
else
lambda { |x| x }
end
end
def initialize def initialize
# :nodoc: # :nodoc:
IO.popen(['debci', 'config', *members.map(&:to_s)]) do |data| IO.popen(['debci', 'config', *members.map(&:to_s)]) do |data|
data.each_line.each do |line| data.each_line.each do |line|
key, value = line.strip.split('=') key, value = line.strip.split('=')
if key =~ /_list$/ cast = self.class.cast_for(key)
value = value.split value = cast.call(value)
end
if key == "quiet"
value = (value == 'true')
end
self.send("#{key}=", value) self.send("#{key}=", value)
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment