13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/flexible_enum/mixin.rb', line 13
def flexible_enum(attribute_name, attribute_options = {}, &config)
feature_module = Module.new do |m|
extend ActiveSupport::Concern
const_set :ClassMethods, Module.new
def m.inspect
"FlexibleEnum(#{self})"
end
end
module_for_elements = attribute_options[:namespace] ? self.const_set(attribute_options[:namespace], Module.new) : feature_module
elements = Configuration.load(&config).elements
configurators = [ConstantConfigurator,
IdentityConfigurator,
QuestionMethodConfigurator,
SetterMethodConfigurator,
ScopeConfigurator,
PotentialValuesConfigurator]
configurators.each do |configurator|
configurator.new(feature_module, attribute_name, module_for_elements, elements).apply
end
send(:include, feature_module)
flexible_enums[attribute_name] = public_send("#{attribute_name.to_s.pluralize}_by_sym")
end
|