lib/power_enum/enumerated.rb in power_enum-3.0.0 vs lib/power_enum/enumerated.rb in power_enum-3.0.1
- old
+ new
@@ -124,10 +124,11 @@
include PowerEnum::Enumerated::EnumInstanceMethods
before_save :enumeration_model_update
before_destroy :enumeration_model_update
validates acts_enumerated_name_column, :presence => true, :uniqueness => true
+ validate :validate_enumeration_model_updates_permitted
define_method :__enum_name__ do
read_attribute(acts_enumerated_name_column).to_s
end
@@ -487,18 +488,27 @@
# rather dangerous because of rails' per-process model.
# The cached values could get out of synch between processes
# and rather than completely disallow changes I make you jump
# through an extra hoop just in case you're defining your enumeration
# values in Migrations. I.e. set enumeration_model_updates_permitted = true
- def enumeration_model_update
+ private def enumeration_model_update
if self.class.enumeration_model_updates_permitted
self.class.purge_enumerations_cache
true
else
# Ugh. This just seems hack-ish. I wonder if there's a better way.
+ if Rails.version =~ /^4\.2\.*/
+ false
+ else
+ throw(:abort)
+ end
+ end
+ end
+
+ # Validates that model updates are enabled.
+ private def validate_enumeration_model_updates_permitted
+ unless self.class.enumeration_model_updates_permitted
self.errors.add(self.class.name_column, "changes to acts_as_enumeration model instances are not permitted")
- false
end
end
- private :enumeration_model_update
end # module EnumInstanceMethods
end # module PowerEnum::Enumerated