power_enum 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b39bcade27495ba688e133624698a3ceee5bb110
|
4
|
+
data.tar.gz: 4746b9693e7654d1aebe60d4ea630238f86049ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 740aeb7bfa76588c6fdc3409997154c06109ce7f24aeacb3b615d48fe5e8b02fb9a2a2adf58ab3c762057a242b812122b569379f1e0420c9152a20d0a69af4b1
|
7
|
+
data.tar.gz: 346e432d2668bc26bf21a9a6145f5ee1642ddf8e07981a698e418a5896ecfb9744e4cd21c5b5e27f760e4f92d681a4bd464910ae52cf13d578dc320127f5dd6d
|
@@ -126,6 +126,7 @@ module PowerEnum::Enumerated
|
|
126
126
|
before_save :enumeration_model_update
|
127
127
|
before_destroy :enumeration_model_update
|
128
128
|
validates acts_enumerated_name_column, :presence => true, :uniqueness => true
|
129
|
+
validate :validate_enumeration_model_updates_permitted
|
129
130
|
|
130
131
|
define_method :__enum_name__ do
|
131
132
|
read_attribute(acts_enumerated_name_column).to_s
|
@@ -489,16 +490,25 @@ module PowerEnum::Enumerated
|
|
489
490
|
# and rather than completely disallow changes I make you jump
|
490
491
|
# through an extra hoop just in case you're defining your enumeration
|
491
492
|
# values in Migrations. I.e. set enumeration_model_updates_permitted = true
|
492
|
-
def enumeration_model_update
|
493
|
+
private def enumeration_model_update
|
493
494
|
if self.class.enumeration_model_updates_permitted
|
494
495
|
self.class.purge_enumerations_cache
|
495
496
|
true
|
496
497
|
else
|
497
498
|
# Ugh. This just seems hack-ish. I wonder if there's a better way.
|
499
|
+
if Rails.version =~ /^4\.2\.*/
|
500
|
+
false
|
501
|
+
else
|
502
|
+
throw(:abort)
|
503
|
+
end
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
# Validates that model updates are enabled.
|
508
|
+
private def validate_enumeration_model_updates_permitted
|
509
|
+
unless self.class.enumeration_model_updates_permitted
|
498
510
|
self.errors.add(self.class.name_column, "changes to acts_as_enumeration model instances are not permitted")
|
499
|
-
false
|
500
511
|
end
|
501
512
|
end
|
502
|
-
private :enumeration_model_update
|
503
513
|
end # module EnumInstanceMethods
|
504
514
|
end # module PowerEnum::Enumerated
|