forked from sous-chefs/haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.rb
32 lines (32 loc) · 847 Bytes
/
default.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# No namespace!?
module ChefHaproxy
class << self
def config_generator(thing, prefix)
result = []
case thing
when Hash
thing.each do |key, value|
case value
when Hash, Array
result.push config_generator(
value, [prefix, key.to_s].compact.join(' ')
)
when TrueClass, FalseClass
if(value)
result << [prefix, key.to_s].compact.join(' ')
end
else
result << [prefix, key.to_s, value.to_s].compact.join(' ')
end
end
when Array
thing.each do |v|
result << [prefix, v.to_s].compact.join(' ')
end
else
raise TypeError.new("Expecting Hash or Array type. Received: #{thing.class}")
end
result.join("\n")
end
end
end