11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/enumerative/has_enumeration.rb', line 11
def has_enumeration( *attributes )
options = attributes.
class_name = if options[:from].try( :is_a?, Class )
options[:from].name
else
options[:from]
end
if class_name && !class_name.constantize.include?( Enumeration )
raise ArgumentError,
':from option should refer to a class that mixes in Enumeration'
end
attributes.each do |a|
composed_of a, :allow_nil => true,
:class_name => class_name || a.to_s.classify,
:mapping => [a, 'key'],
:converter => :new
validates_associated a, :allow_blank => true
end
end
|