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: b2ba1df5d5a34dddc9be7b609aa4199fc2c6a996
4
- data.tar.gz: 9bb8768b88f047dc4a51aa65e37fe693aa4fde3d
3
+ metadata.gz: b39bcade27495ba688e133624698a3ceee5bb110
4
+ data.tar.gz: 4746b9693e7654d1aebe60d4ea630238f86049ec
5
5
  SHA512:
6
- metadata.gz: 5422edc2be751e1600cbbb121d08fdebeae474906466326fc71f3b79650af60a54766bca362a63edf817bc992414e3dd40c962b4f0e6f4308fa6389cd8bb0571
7
- data.tar.gz: a23a77a642de5ded4564d3aec2e946a87dd5ec39ccad94bced7f50cc70431c3b0114ff7d6a4d96514638887c47223dc330820ec8e59752291f8b1c2cf2df64ab
6
+ metadata.gz: 740aeb7bfa76588c6fdc3409997154c06109ce7f24aeacb3b615d48fe5e8b02fb9a2a2adf58ab3c762057a242b812122b569379f1e0420c9152a20d0a69af4b1
7
+ data.tar.gz: 346e432d2668bc26bf21a9a6145f5ee1642ddf8e07981a698e418a5896ecfb9744e4cd21c5b5e27f760e4f92d681a4bd464910ae52cf13d578dc320127f5dd6d
@@ -1,4 +1,4 @@
1
- class <%= migration_class_name %> < ActiveRecord::Migration
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= Rails.version =~ /^4\.2\.*/ ? "" : "[5.0]" %>
2
2
 
3
3
  def change
4
4
  create_enum :<%=file_name%><%= ", description: true" if @description %>
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Squires