Created
June 14, 2010 19:56
-
-
Save eric/438215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Facter.case(name, whens) | |
if whens[:default].is_a?(Exception) | |
default = proc { raise whens[:default] } | |
elsif whens[:default].is_a?(Proc) | |
default = whens[:default] | |
elsif whens[:default] | |
default = proc { whens[:default] } | |
else | |
default = proc { |value| raise "Unsupported case for '#{name}': #{value}" } | |
end | |
if value = self[name] | |
if result = whens[value] | |
return result | |
else | |
return default.call(value) | |
end | |
else | |
raise "No value was returned for '#{name}'" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment