lib/simple_enum.rb in simple_enum-1.3.0 vs lib/simple_enum.rb in simple_enum-1.3.1
- old
+ new
@@ -19,11 +19,11 @@
# Base module which gets included in <tt>ActiveRecord::Base</tt>. See documentation
# of +SimpleEnum::ClassMethods+ for more details.
module SimpleEnum
# +SimpleEnum+ version string.
- VERSION = "1.3.0".freeze
+ VERSION = "1.3.1".freeze
class << self
# Provides configurability to SimpleEnum, allows to override some defaults which are
# defined for all uses of +as_enum+. Most options from +as_enum+ are available, such as:
@@ -151,10 +151,12 @@
# if an invalid value is passed to the setter (e.g. a value for which no enumeration exists). if set to
# <tt>false</tt> no exception is thrown and the internal value is set to <tt>nil</tt> (default is <tt>true</tt>)
def as_enum(enum_cd, values, options = {})
options = SimpleEnum.default_options.merge({ :column => "#{enum_cd}_cd" }).merge(options)
options.assert_valid_keys(:column, :whiny, :prefix, :slim, :upcase)
+
+ metaclass = (class << self; self; end)
# convert array to hash...
values = SimpleEnum::EnumHash.new(values)
values_inverted = values.invert
@@ -211,10 +213,10 @@
sym
end
# allow class access to each value
unless options[:slim] === :class
- singleton_class.send(:define_method, "#{prefix}#{sym}", Proc.new { |*args| args.first ? k : code })
+ metaclass.send(:define_method, "#{prefix}#{sym}", Proc.new { |*args| args.first ? k : code })
end
end
end
end