power_enum 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 893addf87676cb3a7a981c4183799d2b67b7c60f
4
- data.tar.gz: a46af4984122a09568cdd6f11ba65114c2a6cde7
3
+ metadata.gz: 64844e550c505a4a4f76be6db166cb8cfe619211
4
+ data.tar.gz: a52e8c4606a8466f4427e8c311d77bc5d0191586
5
5
  SHA512:
6
- metadata.gz: 71d9e4aae317d96629faac94ba16714a1f6ab8b6a3533a4bd19e019d4b38d85ff051965efd58dbf779e2f965e187c3801683ef07c9898811bdb939a2193ec435
7
- data.tar.gz: afbd9d683a316c7d34fbc41480a15960db66048dc55b7b98960e6ce0f7164299ee50a0f0ee90eb307c97f44ca663f34275a0c69bc98ed3627cdd7204a6f32687
6
+ metadata.gz: 8c4eefff7165c2465455555eba9f73a7ecf81d92db1288ebfee7fabf0848cc10ec8c0d71c56485e32df98e5ed1178e827f95c4a6987907f344a8fc188bd29b45
7
+ data.tar.gz: 79fabb30097902433ad93e59ecc1b3397924c65e9ea5526c8fc12334fb51d3fa5d812abd76f7879eba4a8e7735af2a27e27da87c1dae84ba6e9d965bfffc35db
@@ -15,7 +15,12 @@ class PowerEnum < Rails::Engine
15
15
  ActiveSupport.on_load(:active_record) do
16
16
  include PowerEnum::Enumerated
17
17
  include PowerEnum::HasEnumerated
18
- include PowerEnum::Reflection
18
+
19
+ ActiveRecord::Base.module_eval do
20
+ class << self
21
+ prepend ::PowerEnum::Reflection
22
+ end
23
+ end
19
24
 
20
25
  ActiveRecord::ConnectionAdapters.module_eval do
21
26
  include PowerEnum::Schema::SchemaStatements
@@ -5,45 +5,32 @@
5
5
 
6
6
  # Used to patch ActiveRecord reflections.
7
7
  module PowerEnum::Reflection
8
- extend ActiveSupport::Concern
9
-
10
- # Class-level extensions injected into ActiveRecord
11
- module ClassMethods
12
- def self.extended(base) # :nodoc:
13
- class << base
14
- alias_method_chain :reflect_on_all_associations, :enumeration
15
- alias_method_chain :reflect_on_association, :enumeration
16
- end
17
- end
18
8
 
19
- # All {PowerEnum::Reflection::EnumerationReflection} reflections
20
- def reflect_on_all_enumerated
21
- # Need to give it a full namespace to avoid getting Rails confused in development
22
- # mode where all objects are reloaded on every request.
23
- reflections.values.grep(PowerEnum::Reflection::EnumerationReflection)
24
- end
9
+ # All {PowerEnum::Reflection::EnumerationReflection} reflections
10
+ def reflect_on_all_enumerated
11
+ # Need to give it a full namespace to avoid getting Rails confused in development
12
+ # mode where all objects are reloaded on every request.
13
+ reflections.values.grep(PowerEnum::Reflection::EnumerationReflection)
14
+ end
25
15
 
26
- # If the reflection of the given name is an EnumerationReflection, returns
27
- # the reflection, otherwise returns nil.
28
- # @return [PowerEnum::Reflection::EnumerationReflection]
29
- def reflect_on_enumerated( enumerated )
30
- key = if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.0\.*/
31
- enumerated.to_s
32
- else
33
- enumerated.to_sym
34
- end
35
- reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
36
- end
16
+ # If the reflection of the given name is an EnumerationReflection, returns
17
+ # the reflection, otherwise returns nil.
18
+ # @return [PowerEnum::Reflection::EnumerationReflection]
19
+ def reflect_on_enumerated( enumerated )
20
+ key = if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.*/
21
+ enumerated.to_s
22
+ else
23
+ enumerated.to_sym
24
+ end
25
+ reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
26
+ end
37
27
 
38
- # Extend associations with enumerations, preferring enumerations
39
- def reflect_on_all_associations_with_enumeration(macro = nil)
40
- reflect_on_all_enumerated + reflect_on_all_associations_without_enumeration(macro)
41
- end
28
+ def reflect_on_all_associations(macro = nil)
29
+ reflect_on_all_enumerated + super(macro)
30
+ end
42
31
 
43
- # Extend associations with enumerations, preferring enumerations
44
- def reflect_on_association_with_enumeration( associated )
45
- reflect_on_enumerated(associated) || reflect_on_association_without_enumeration(associated)
46
- end
32
+ def reflect_on_association(associated)
33
+ reflect_on_enumerated(associated) || super(associated)
47
34
  end
48
35
 
49
36
  # Reflection class for enum reflections. See ActiveRecord::Reflection
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: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Squires
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-05-25 00:00:00.000000000 Z
14
+ date: 2017-08-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler