power_enum 3.0.1 → 3.4.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 +5 -5
- data/README.markdown +10 -6
- data/lib/power_enum/enumerated.rb +5 -0
- data/lib/power_enum/reflection.rb +13 -0
- metadata +16 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e64bc976c66ec97d00cd14baabeb0fa7c13afc66500bb8408bc9d1e884be30ee
|
|
4
|
+
data.tar.gz: 43f0a3fa296b90154d32b82a38d8ae207b0b8f400edc821ded353e341ddb5187
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b36b482f22cf0ddc61e817f77838a245a250a3c28771c0d0e39d8e23f29b782abd93fbb06c84fa6b009f66bdb510933b0e292a8ceeed60d190caeeeba24d05f2
|
|
7
|
+
data.tar.gz: 2731947e3bb7d5f9b91fffd726db29ab26451536fc60b8110886d2d8ed3402af9f8f0d10471bea00c83f36e4577476df2fb1c2cdebe106b74d684e80d7637d33
|
data/README.markdown
CHANGED
|
@@ -10,7 +10,7 @@ Enumerations for Rails Done Right.
|
|
|
10
10
|
|
|
11
11
|
## Versions
|
|
12
12
|
|
|
13
|
-
* PowerEnum 3.X (this version) supports Rails 4.2 and Rails
|
|
13
|
+
* PowerEnum 3.X (this version) supports Rails 4.2, Rails 5.X and Rails 6.0
|
|
14
14
|
* PowerEnum 2.X supports Rails 4.X and Rails 5.0
|
|
15
15
|
* PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum
|
|
16
16
|
|
|
@@ -54,7 +54,7 @@ See "How to use it" below for more information.
|
|
|
54
54
|
### PowerEnum 3.X
|
|
55
55
|
|
|
56
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
|
|
57
|
+
* Rails 4.2, 5.0, 5.1, 5.2, 6.0
|
|
58
58
|
|
|
59
59
|
### PowerEnum 2.X
|
|
60
60
|
|
|
@@ -198,7 +198,7 @@ create_table :bookings do |t|
|
|
|
198
198
|
t.timestamps
|
|
199
199
|
end
|
|
200
200
|
```
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
There are two methods added to Rails migrations:
|
|
203
203
|
|
|
204
204
|
##### create\_enum(enum\_name, options = {}, &block)
|
|
@@ -285,7 +285,7 @@ Example:
|
|
|
285
285
|
```ruby
|
|
286
286
|
remove_enum :booking_status
|
|
287
287
|
```
|
|
288
|
-
|
|
288
|
+
|
|
289
289
|
is the equivalent of
|
|
290
290
|
|
|
291
291
|
```ruby
|
|
@@ -341,6 +341,10 @@ other value.
|
|
|
341
341
|
`BookingStatus.all` returns an array of all BookingStatus records that match the `:conditions` specified in
|
|
342
342
|
`acts_as_enumerated`, in the order specified by `:order`.
|
|
343
343
|
|
|
344
|
+
##### all_except(*items)
|
|
345
|
+
|
|
346
|
+
`BookingStatus.all_except(arg1, arg2)` returns an array of all BookingStatus records with the given items filtered out.
|
|
347
|
+
|
|
344
348
|
##### active
|
|
345
349
|
|
|
346
350
|
`BookingStatus.active` returns an array of all BookingStatus records that are marked active. See the `active?` instance
|
|
@@ -784,7 +788,7 @@ Execute the test setup script:
|
|
|
784
788
|
#### Manually (if required)
|
|
785
789
|
|
|
786
790
|
Go to the 'dummy' project:
|
|
787
|
-
|
|
791
|
+
|
|
788
792
|
cd ./spec/dummy
|
|
789
793
|
|
|
790
794
|
If this is your first time, create the test database
|
|
@@ -808,7 +812,7 @@ Go back to gem root directory:
|
|
|
808
812
|
* Initial Version Copyright (c) 2005 Trevor Squires
|
|
809
813
|
* Rails 3 Updates Copyright (c) 2010 Pivotal Labs
|
|
810
814
|
* Initial Test Suite Copyright (c) 2011 Sergey Potapov
|
|
811
|
-
* Subsequent Updates Copyright (c) 2011-
|
|
815
|
+
* Subsequent Updates Copyright (c) 2011-2020 Arthur Shagall
|
|
812
816
|
|
|
813
817
|
Released under the MIT License. See the LICENSE file for more details.
|
|
814
818
|
|
|
@@ -194,6 +194,11 @@ module PowerEnum::Enumerated
|
|
|
194
194
|
all.map { |item| item.name_sym }
|
|
195
195
|
end
|
|
196
196
|
|
|
197
|
+
# Returns all except for the given list
|
|
198
|
+
def all_except(*excluded)
|
|
199
|
+
all.find_all { |item| !(item === excluded) }
|
|
200
|
+
end
|
|
201
|
+
|
|
197
202
|
# Enum lookup by Symbol, String, or id. Returns <tt>arg<tt> if arg is
|
|
198
203
|
# an enum instance. Passing in a list of arguments returns a list of
|
|
199
204
|
# enums. When called with no arguments, returns nil.
|
|
@@ -63,10 +63,16 @@ of these associations is deprecated and will be removed in the future.
|
|
|
63
63
|
@active_record_primary_key ||= options[:primary_key] || active_record.primary_key
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
alias_method :join_primary_key, :active_record_primary_key
|
|
67
|
+
|
|
66
68
|
def klass
|
|
67
69
|
@klass ||= active_record.send(:compute_type, class_name)
|
|
68
70
|
end
|
|
69
71
|
|
|
72
|
+
def association_class
|
|
73
|
+
::ActiveRecord::Associations::HasOneAssociation
|
|
74
|
+
end
|
|
75
|
+
|
|
70
76
|
EnumJoinKeys = Struct.new(:key, :foreign_key)
|
|
71
77
|
|
|
72
78
|
def join_keys(*_)
|
|
@@ -83,6 +89,8 @@ of these associations is deprecated and will be removed in the future.
|
|
|
83
89
|
@foreign_key ||= (@options[:foreign_key] || "#{@name}_id").to_s
|
|
84
90
|
end
|
|
85
91
|
|
|
92
|
+
alias_method :join_foreign_key, :foreign_key
|
|
93
|
+
|
|
86
94
|
# Returns the name of the enum table
|
|
87
95
|
def table_name
|
|
88
96
|
@table_name ||= self.class.const_get(class_name).table_name
|
|
@@ -112,6 +120,11 @@ of these associations is deprecated and will be removed in the future.
|
|
|
112
120
|
false
|
|
113
121
|
end
|
|
114
122
|
|
|
123
|
+
# Always returns true.
|
|
124
|
+
def collection?
|
|
125
|
+
true
|
|
126
|
+
end
|
|
127
|
+
|
|
115
128
|
# In this case, returns [[]]
|
|
116
129
|
def conditions
|
|
117
130
|
[[]]
|
metadata
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: power_enum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0
|
|
4
|
+
version: 3.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Trevor Squires
|
|
8
8
|
- Pivotal Labs
|
|
9
9
|
- Arthur Shagall
|
|
10
10
|
- Sergey Potapov
|
|
11
|
-
autorequire:
|
|
11
|
+
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date:
|
|
14
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: bundler
|
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
|
19
19
|
requirements:
|
|
20
|
-
- - "
|
|
20
|
+
- - ">"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '1.
|
|
22
|
+
version: '1.7'
|
|
23
23
|
type: :development
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
|
-
- - "
|
|
27
|
+
- - ">"
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '1.
|
|
29
|
+
version: '1.7'
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: rake
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -64,7 +64,7 @@ dependencies:
|
|
|
64
64
|
version: '4.2'
|
|
65
65
|
- - "<"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '
|
|
67
|
+
version: '7'
|
|
68
68
|
type: :development
|
|
69
69
|
prerelease: false
|
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -74,7 +74,7 @@ dependencies:
|
|
|
74
74
|
version: '4.2'
|
|
75
75
|
- - "<"
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: '
|
|
77
|
+
version: '7'
|
|
78
78
|
- !ruby/object:Gem::Dependency
|
|
79
79
|
name: railties
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,7 +84,7 @@ dependencies:
|
|
|
84
84
|
version: '4.2'
|
|
85
85
|
- - "<"
|
|
86
86
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '
|
|
87
|
+
version: '7'
|
|
88
88
|
type: :runtime
|
|
89
89
|
prerelease: false
|
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -94,7 +94,7 @@ dependencies:
|
|
|
94
94
|
version: '4.2'
|
|
95
95
|
- - "<"
|
|
96
96
|
- !ruby/object:Gem::Version
|
|
97
|
-
version: '
|
|
97
|
+
version: '7'
|
|
98
98
|
- !ruby/object:Gem::Dependency
|
|
99
99
|
name: activerecord
|
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -104,7 +104,7 @@ dependencies:
|
|
|
104
104
|
version: '4.2'
|
|
105
105
|
- - "<"
|
|
106
106
|
- !ruby/object:Gem::Version
|
|
107
|
-
version: '
|
|
107
|
+
version: '7'
|
|
108
108
|
type: :runtime
|
|
109
109
|
prerelease: false
|
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -114,7 +114,7 @@ dependencies:
|
|
|
114
114
|
version: '4.2'
|
|
115
115
|
- - "<"
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: '
|
|
117
|
+
version: '7'
|
|
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.
|
|
@@ -149,7 +149,7 @@ homepage: http://github.com/albertosaurus/power_enum_2
|
|
|
149
149
|
licenses:
|
|
150
150
|
- MIT
|
|
151
151
|
metadata: {}
|
|
152
|
-
post_install_message:
|
|
152
|
+
post_install_message:
|
|
153
153
|
rdoc_options: []
|
|
154
154
|
require_paths:
|
|
155
155
|
- lib
|
|
@@ -164,9 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
164
164
|
- !ruby/object:Gem::Version
|
|
165
165
|
version: '0'
|
|
166
166
|
requirements: []
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
signing_key:
|
|
167
|
+
rubygems_version: 3.0.8
|
|
168
|
+
signing_key:
|
|
170
169
|
specification_version: 4
|
|
171
170
|
summary: Allows you to treat instances of your ActiveRecord models as though they
|
|
172
171
|
were an enumeration of values
|