power_enum 2.12.0 → 3.0.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/README.markdown +8 -2
- data/lib/power_enum/has_enumerated.rb +1 -11
- data/lib/power_enum/reflection.rb +23 -32
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ba1df5d5a34dddc9be7b609aa4199fc2c6a996
|
4
|
+
data.tar.gz: 9bb8768b88f047dc4a51aa65e37fe693aa4fde3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5422edc2be751e1600cbbb121d08fdebeae474906466326fc71f3b79650af60a54766bca362a63edf817bc992414e3dd40c962b4f0e6f4308fa6389cd8bb0571
|
7
|
+
data.tar.gz: a23a77a642de5ded4564d3aec2e946a87dd5ec39ccad94bced7f50cc70431c3b0114ff7d6a4d96514638887c47223dc330820ec8e59752291f8b1c2cf2df64ab
|
data/README.markdown
CHANGED
@@ -10,7 +10,8 @@ Enumerations for Rails Done Right.
|
|
10
10
|
|
11
11
|
## Versions
|
12
12
|
|
13
|
-
* PowerEnum
|
13
|
+
* PowerEnum 3.X (this version) supports Rails 4.2 and Rails 5.X
|
14
|
+
* PowerEnum 2.X supports Rails 4.X and Rails 5.0
|
14
15
|
* PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum
|
15
16
|
|
16
17
|
## What is this?:
|
@@ -50,10 +51,15 @@ See "How to use it" below for more information.
|
|
50
51
|
|
51
52
|
## Requirements
|
52
53
|
|
54
|
+
### PowerEnum 3.X
|
55
|
+
|
56
|
+
* Ruby 2.1 or later (JRuby should work but isn't extensively tested; Travis is being difficult).
|
57
|
+
* Rails 4.2, 5.0, 5.1
|
58
|
+
|
53
59
|
### PowerEnum 2.X
|
54
60
|
|
55
61
|
* Ruby 1.9.3, 2.0, JRuby 1.7+ (Ruby 1.9.3 or 2.0 required for development)
|
56
|
-
* Rails 4.0
|
62
|
+
* Rails 4.0, 4.1, 4.2, 5.0
|
57
63
|
|
58
64
|
## Installation
|
59
65
|
|
@@ -125,17 +125,7 @@ module PowerEnum::HasEnumerated
|
|
125
125
|
def create_ar_reflection(part_id, options)
|
126
126
|
reflection = PowerEnum::Reflection::EnumerationReflection.new(part_id, options, self)
|
127
127
|
|
128
|
-
|
129
|
-
if self.respond_to? :_reflections=
|
130
|
-
if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.0\.*/
|
131
|
-
self._reflections = self._reflections.merge(part_id.to_s => reflection)
|
132
|
-
else
|
133
|
-
self._reflections = self._reflections.merge(part_id => reflection)
|
134
|
-
end
|
135
|
-
|
136
|
-
else
|
137
|
-
self.reflections = self.reflections.merge(part_id => reflection)
|
138
|
-
end
|
128
|
+
self._reflections = self._reflections.merge(part_id.to_s => reflection)
|
139
129
|
reflection
|
140
130
|
end
|
141
131
|
private :create_ar_reflection
|
@@ -17,11 +17,7 @@ module PowerEnum::Reflection
|
|
17
17
|
# the reflection, otherwise returns nil.
|
18
18
|
# @return [PowerEnum::Reflection::EnumerationReflection]
|
19
19
|
def reflect_on_enumerated( enumerated )
|
20
|
-
key =
|
21
|
-
enumerated.to_s
|
22
|
-
else
|
23
|
-
enumerated.to_sym
|
24
|
-
end
|
20
|
+
key = enumerated.to_s
|
25
21
|
reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
|
26
22
|
end
|
27
23
|
|
@@ -39,47 +35,42 @@ module PowerEnum::Reflection
|
|
39
35
|
attr_accessor :parent_reflection
|
40
36
|
|
41
37
|
# See ActiveRecord::Reflection::MacroReflection
|
42
|
-
def initialize(
|
43
|
-
|
44
|
-
super name, nil, options, active_record
|
45
|
-
else
|
46
|
-
super :has_enumerated, name, nil, options, active_record
|
47
|
-
end
|
38
|
+
def initialize(name, options, active_record)
|
39
|
+
super name, nil, options, active_record
|
48
40
|
end
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
42
|
+
def macro
|
43
|
+
:has_enumerated
|
44
|
+
end
|
54
45
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
def check_preloadable!
|
47
|
+
return unless scope
|
48
|
+
if scope.arity > 0
|
49
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
59
50
|
The association scope '#{name}' is instance dependent (the scope
|
60
51
|
block takes an argument). Preloading happens before the individual
|
61
52
|
instances are created. This means that there is no instance being
|
62
53
|
passed to the association scope. This will most likely result in
|
63
54
|
broken or incorrect behavior. Joining, Preloading and eager loading
|
64
55
|
of these associations is deprecated and will be removed in the future.
|
65
|
-
|
66
|
-
end
|
56
|
+
MSG
|
67
57
|
end
|
68
|
-
|
58
|
+
end
|
69
59
|
|
70
|
-
|
71
|
-
@active_record_primary_key ||= options[:primary_key] || active_record.primary_key
|
72
|
-
end
|
60
|
+
alias :check_eager_loadable! :check_preloadable!
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
def active_record_primary_key
|
63
|
+
@active_record_primary_key ||= options[:primary_key] || active_record.primary_key
|
64
|
+
end
|
77
65
|
|
78
|
-
|
66
|
+
def klass
|
67
|
+
@klass ||= active_record.send(:compute_type, class_name)
|
68
|
+
end
|
79
69
|
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
EnumJoinKeys = Struct.new(:key, :foreign_key)
|
71
|
+
|
72
|
+
def join_keys(*_)
|
73
|
+
EnumJoinKeys.new(active_record_primary_key, foreign_key)
|
83
74
|
end
|
84
75
|
|
85
76
|
# Returns the class name of the enum
|
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:
|
4
|
+
version: 3.0.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-08-
|
14
|
+
date: 2017-08-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -61,60 +61,60 @@ dependencies:
|
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '4.
|
64
|
+
version: '4.2'
|
65
65
|
- - "<"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '5.
|
67
|
+
version: '5.2'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '4.
|
74
|
+
version: '4.2'
|
75
75
|
- - "<"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '5.
|
77
|
+
version: '5.2'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: railties
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '4.
|
84
|
+
version: '4.2'
|
85
85
|
- - "<"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '5.
|
87
|
+
version: '5.2'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '4.
|
94
|
+
version: '4.2'
|
95
95
|
- - "<"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '5.
|
97
|
+
version: '5.2'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: activerecord
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '4.
|
104
|
+
version: '4.2'
|
105
105
|
- - "<"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: '5.
|
107
|
+
version: '5.2'
|
108
108
|
type: :runtime
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: '4.
|
114
|
+
version: '4.2'
|
115
115
|
- - "<"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '5.
|
117
|
+
version: '5.2'
|
118
118
|
description: |
|
119
119
|
Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
|
120
120
|
It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.
|