21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/dimensional/enum.rb', line 21
def def_enum( enum_key )
if @enum_attributes.nil?
raise ::Dimensional::Enum::InvalidDefinition, "Undefined @enum_attributes on #{self}"
end
unless @enum_attributes.include? enum_key
raise ::Dimensional::Enum::InvalidDefinition, "Undefined enum_key #{enum_key} in @enum_attributes"
end
enum_values = @enum_attributes.to_value_h( enum_key )
enum_attribute = @enum_attributes.to_attribute_h( enum_key )
self.class_eval do
enum enum_key => enum_values
define_method enum_key do
return nil unless attr_key = super()
::Dimensional::Enum::Attribute.new attr_key, enum_attribute
end
end
end
|