power_enum 3.5.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +17 -10
- data/VERSION +1 -0
- data/lib/power_enum/enumerated.rb +436 -431
- data/lib/power_enum/has_enumerated.rb +175 -172
- data/lib/power_enum/schema/schema_statements.rb +4 -2
- data/lib/power_enum.rb +26 -16
- metadata +21 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d082903c63c4312b09017f253ab915ce20548fae15d69472afa0781a8880354
|
4
|
+
data.tar.gz: 726cf42b46643730d6999adb7f7ecebbbc0dd952cecca428ffaac153555cabee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5c5ef9ffde3a15bea67001ad4c27763488268ed6d850f0e8a25bde2a1ce24b48e4f5db979c90aa4de95c32f9e7ac51825fc6909dd2594cb5b2dbf7de59490d3
|
7
|
+
data.tar.gz: e4ca6e0641f07b4d0357b260e17175263094f4fe8234f195082a69527ebc7384b6ecb5ee42bf7fd02f2c7322cbe816dede2d403bd494d5096cfb72d0fe0ff26f
|
data/README.markdown
CHANGED
@@ -10,7 +10,8 @@ Enumerations for Rails Done Right.
|
|
10
10
|
|
11
11
|
## Versions
|
12
12
|
|
13
|
-
* PowerEnum
|
13
|
+
* PowerEnum 4.0.X (this version) supports Rails 6.X, and Rails 7.0 (Experimental)
|
14
|
+
* PowerEnum 3.X supports Rails 4.2, Rails 5.X and Rails 6.0
|
14
15
|
* PowerEnum 2.X supports Rails 4.X and Rails 5.0
|
15
16
|
* PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum
|
16
17
|
|
@@ -29,16 +30,17 @@ At it's most basic level, it allows you to say things along the lines of:
|
|
29
30
|
|
30
31
|
```ruby
|
31
32
|
# Create a provisional booking
|
32
|
-
booking = Booking.new( :
|
33
|
+
booking = Booking.new( status: BookingStatus[:provisional] )
|
33
34
|
# This also works
|
34
|
-
booking = Booking.new( :
|
35
|
+
booking = Booking.new( status: :provisional )
|
35
36
|
# Set the booking status to 'confirmed'
|
36
37
|
booking.status = :confirmed
|
37
|
-
booking = Booking.create( :
|
38
|
+
booking = Booking.create( status: :rejected )
|
38
39
|
# And now...
|
39
40
|
booking.status == BookingStatus[:rejected] # evaluates to true
|
40
41
|
booking.status === :rejected # also evaluates to true
|
41
42
|
booking.status === [:rejected, :confirmed, :provisional] # and so does this
|
43
|
+
booking.status === [%i[rejected confirmed provisional]] # and this
|
42
44
|
|
43
45
|
Booking.where( :status_id => BookingStatus[:provisional] )
|
44
46
|
|
@@ -51,9 +53,14 @@ See "How to use it" below for more information.
|
|
51
53
|
|
52
54
|
## Requirements
|
53
55
|
|
56
|
+
### PowerEnum 4.0.X
|
57
|
+
|
58
|
+
* Ruby 2.7 or later (JRuby should work but isn't extensively tested).
|
59
|
+
* Rails 6.0, 6.1, 6.2, 7.0
|
60
|
+
|
54
61
|
### PowerEnum 3.X
|
55
62
|
|
56
|
-
* Ruby 2.1 or later (JRuby should work but isn't extensively tested
|
63
|
+
* Ruby 2.1 or later (JRuby should work but isn't extensively tested).
|
57
64
|
* Rails 4.2, 5.0, 5.1, 5.2, 6.0
|
58
65
|
|
59
66
|
### PowerEnum 2.X
|
@@ -77,10 +84,6 @@ then run
|
|
77
84
|
|
78
85
|
gem install power_enum
|
79
86
|
|
80
|
-
If you want to verify the gem signature, use the `HighSecurity` installation option.
|
81
|
-
|
82
|
-
gem install power_enum -P HighSecurity
|
83
|
-
|
84
87
|
## Gem Contents
|
85
88
|
|
86
89
|
This package adds:
|
@@ -151,6 +154,8 @@ create_enum :booking_status, :name_limit => 50
|
|
151
154
|
# end
|
152
155
|
```
|
153
156
|
|
157
|
+
**WARNING - This conflicts with PostgreSQL enum support in Rails 7+ and will be renamed in future versions.**
|
158
|
+
|
154
159
|
Now, when you create your Booking model, your migration should create a reference column for status id's and a foreign
|
155
160
|
key relationship to the booking\_statuses table.
|
156
161
|
|
@@ -162,7 +167,7 @@ create_table :bookings do |t|
|
|
162
167
|
end
|
163
168
|
|
164
169
|
# It's highly recommended to add a foreign key constraint here.
|
165
|
-
# Ideally, you would use a gem of some sort to handle this.
|
170
|
+
# Ideally, you would use a gem of some sort to handle this for Rails < 6.
|
166
171
|
# I have been using PgPower https://rubygems.org/gems/pg_power with much
|
167
172
|
# success. It's fork, PgSaurus https://rubygems.org/gems/pg_saurus should
|
168
173
|
# work just as well.
|
@@ -184,6 +189,8 @@ There are two methods added to Rails migrations:
|
|
184
189
|
|
185
190
|
##### create\_enum(enum\_name, options = {}, &block)
|
186
191
|
|
192
|
+
**WARNING - This conflicts with PostgreSQL enum support in Rails 7+ and will be renamed in future versions.**
|
193
|
+
|
187
194
|
Creates a new enum table. `enum_name` will be automatically pluralized. The following options are supported:
|
188
195
|
|
189
196
|
- [:name\_column] Specify the column name for name of the enum. By default it's :name. This can be a String or a Symbol
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
4.0.1
|