Possible Ruby Enum Fix (#6131)

This commit is contained in:
NicoEigenmannCW 2017-07-21 16:26:39 +02:00 committed by wing328
parent 1f133e8ecd
commit b9b1b7647b

View File

@ -1,4 +1,13 @@
class {{classname}} class {{classname}}
{{#allowableValues}}{{#enumVars}} {{#allowableValues}}{{#enumVars}}
{{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}} {{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}}
# Builds the enum from string
# @param [String] The enum value in the form of the string
# @return [String] The enum value
def build_from_hash(value)
consantValues = {{classname}}.constants.select{|c| c.to_s == value}
raise "Invalid ENUM value #{value} for class #{{{classname}}}" if consantValues.empty?
value
end
end end