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 +4 -4
- data/lib/power_enum.rb +6 -1
- data/lib/power_enum/reflection.rb +22 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64844e550c505a4a4f76be6db166cb8cfe619211
|
4
|
+
data.tar.gz: a52e8c4606a8466f4427e8c311d77bc5d0191586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c4eefff7165c2465455555eba9f73a7ecf81d92db1288ebfee7fabf0848cc10ec8c0d71c56485e32df98e5ed1178e827f95c4a6987907f344a8fc188bd29b45
|
7
|
+
data.tar.gz: 79fabb30097902433ad93e59ecc1b3397924c65e9ea5526c8fc12334fb51d3fa5d812abd76f7879eba4a8e7735af2a27e27da87c1dae84ba6e9d965bfffc35db
|
data/lib/power_enum.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
28
|
+
def reflect_on_all_associations(macro = nil)
|
29
|
+
reflect_on_all_enumerated + super(macro)
|
30
|
+
end
|
42
31
|
|
43
|
-
|
44
|
-
|
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.
|
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-
|
14
|
+
date: 2017-08-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|