enum_machine 2.1.0 → 2.3.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/.rubocop.yml +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +88 -67
- data/README.md +77 -7
- data/enum_machine.gemspec +41 -0
- data/lib/enum_machine/build_enum_class.rb +1 -1
- data/lib/enum_machine/driver_simple_class.rb +1 -2
- data/lib/enum_machine/version.rb +1 -1
- data/lib/enum_machine.rb +9 -0
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86f84c741963ae08afc9fc2072a816140b13a8f819fecf2739460cf1118ac10d
|
|
4
|
+
data.tar.gz: c8eea28785d2845c8ccaf8892f9c63f8e600054b5e8c74998656f1fbda3ced97
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db343c2b699f2d00ead6c0ae58a033b3269e4680f55711eb82b136ed0c7092ec3365ce6b5cddd19d28378f2cf1952d67e5e411f6fb97d9a0059ad7ca79a1af5d
|
|
7
|
+
data.tar.gz: 98e5ad6a7e5ecff10a12c96f2d24a1d19b75b7903bd55fa70aec36d628502ed090d0568d0f5e9ddbd941e08804171d4ad0e09d84dc44b3836d33aca55545c33c
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -8,7 +8,7 @@ GIT
|
|
|
8
8
|
|
|
9
9
|
GIT
|
|
10
10
|
remote: https://github.com/corp-gp/rubocop-gp.git
|
|
11
|
-
revision:
|
|
11
|
+
revision: e3d33016bb3b9945ce9d8d22e77825a223de1a5c
|
|
12
12
|
specs:
|
|
13
13
|
rubocop-gp (0.0.4)
|
|
14
14
|
rubocop
|
|
@@ -22,7 +22,7 @@ GIT
|
|
|
22
22
|
PATH
|
|
23
23
|
remote: .
|
|
24
24
|
specs:
|
|
25
|
-
enum_machine (2.0
|
|
25
|
+
enum_machine (2.3.0)
|
|
26
26
|
activemodel
|
|
27
27
|
activerecord
|
|
28
28
|
activesupport
|
|
@@ -30,125 +30,146 @@ PATH
|
|
|
30
30
|
GEM
|
|
31
31
|
remote: https://rubygems.org/
|
|
32
32
|
specs:
|
|
33
|
-
activemodel (
|
|
34
|
-
activesupport (=
|
|
35
|
-
activerecord (
|
|
36
|
-
activemodel (=
|
|
37
|
-
activesupport (=
|
|
33
|
+
activemodel (8.1.2)
|
|
34
|
+
activesupport (= 8.1.2)
|
|
35
|
+
activerecord (8.1.2)
|
|
36
|
+
activemodel (= 8.1.2)
|
|
37
|
+
activesupport (= 8.1.2)
|
|
38
38
|
timeout (>= 0.4.0)
|
|
39
|
-
activesupport (
|
|
39
|
+
activesupport (8.1.2)
|
|
40
40
|
base64
|
|
41
41
|
bigdecimal
|
|
42
42
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
43
43
|
connection_pool (>= 2.2.5)
|
|
44
44
|
drb
|
|
45
45
|
i18n (>= 1.6, < 2)
|
|
46
|
+
json
|
|
46
47
|
logger (>= 1.4.2)
|
|
47
48
|
minitest (>= 5.1)
|
|
48
49
|
securerandom (>= 0.3)
|
|
49
50
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
uri (>= 0.13.1)
|
|
52
|
+
ast (2.4.3)
|
|
53
|
+
base64 (0.3.0)
|
|
54
|
+
bigdecimal (4.0.1)
|
|
53
55
|
coderay (1.1.3)
|
|
54
56
|
colorize (0.8.1)
|
|
55
|
-
concurrent-ruby (1.3.
|
|
56
|
-
connection_pool (
|
|
57
|
-
diff-lcs (1.
|
|
58
|
-
drb (2.2.
|
|
59
|
-
dry-core (1.0
|
|
57
|
+
concurrent-ruby (1.3.6)
|
|
58
|
+
connection_pool (3.0.2)
|
|
59
|
+
diff-lcs (1.6.2)
|
|
60
|
+
drb (2.2.3)
|
|
61
|
+
dry-core (1.2.0)
|
|
60
62
|
concurrent-ruby (~> 1.0)
|
|
63
|
+
logger
|
|
61
64
|
zeitwerk (~> 2.6)
|
|
62
|
-
dry-inflector (1.
|
|
63
|
-
dry-logic (1.
|
|
65
|
+
dry-inflector (1.3.0)
|
|
66
|
+
dry-logic (1.6.0)
|
|
67
|
+
bigdecimal
|
|
64
68
|
concurrent-ruby (~> 1.0)
|
|
65
|
-
dry-core (~> 1.
|
|
69
|
+
dry-core (~> 1.1)
|
|
66
70
|
zeitwerk (~> 2.6)
|
|
67
|
-
dry-types (1.
|
|
68
|
-
bigdecimal (
|
|
71
|
+
dry-types (1.9.0)
|
|
72
|
+
bigdecimal (>= 3.0)
|
|
69
73
|
concurrent-ruby (~> 1.0)
|
|
70
74
|
dry-core (~> 1.0)
|
|
71
75
|
dry-inflector (~> 1.0)
|
|
72
76
|
dry-logic (~> 1.4)
|
|
73
77
|
zeitwerk (~> 2.6)
|
|
74
|
-
i18n (1.14.
|
|
78
|
+
i18n (1.14.8)
|
|
75
79
|
concurrent-ruby (~> 1.0)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
io-console (0.8.2)
|
|
81
|
+
json (2.18.0)
|
|
82
|
+
language_server-protocol (3.17.0.5)
|
|
83
|
+
lint_roller (1.1.0)
|
|
84
|
+
logger (1.7.0)
|
|
79
85
|
method_source (1.1.0)
|
|
80
|
-
minitest (
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
minitest (6.0.1)
|
|
87
|
+
prism (~> 1.5)
|
|
88
|
+
parallel (1.27.0)
|
|
89
|
+
parser (3.3.10.0)
|
|
83
90
|
ast (~> 2.4.1)
|
|
84
91
|
racc
|
|
85
|
-
|
|
92
|
+
prism (1.7.0)
|
|
93
|
+
pry (0.16.0)
|
|
86
94
|
coderay (~> 1.1)
|
|
87
95
|
method_source (~> 1.0)
|
|
96
|
+
reline (>= 0.6.0)
|
|
88
97
|
racc (1.8.1)
|
|
89
|
-
rack (3.
|
|
98
|
+
rack (3.2.4)
|
|
90
99
|
rainbow (3.1.1)
|
|
91
|
-
rake (13.
|
|
92
|
-
regexp_parser (2.
|
|
93
|
-
|
|
100
|
+
rake (13.3.1)
|
|
101
|
+
regexp_parser (2.11.3)
|
|
102
|
+
reline (0.6.3)
|
|
103
|
+
io-console (~> 0.5)
|
|
104
|
+
rspec (3.13.2)
|
|
94
105
|
rspec-core (~> 3.13.0)
|
|
95
106
|
rspec-expectations (~> 3.13.0)
|
|
96
107
|
rspec-mocks (~> 3.13.0)
|
|
97
|
-
rspec-core (3.13.
|
|
108
|
+
rspec-core (3.13.6)
|
|
98
109
|
rspec-support (~> 3.13.0)
|
|
99
|
-
rspec-expectations (3.13.
|
|
110
|
+
rspec-expectations (3.13.5)
|
|
100
111
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
101
112
|
rspec-support (~> 3.13.0)
|
|
102
|
-
rspec-mocks (3.13.
|
|
113
|
+
rspec-mocks (3.13.7)
|
|
103
114
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
104
115
|
rspec-support (~> 3.13.0)
|
|
105
|
-
rspec-support (3.13.
|
|
106
|
-
rubocop (1.
|
|
116
|
+
rspec-support (3.13.6)
|
|
117
|
+
rubocop (1.82.1)
|
|
107
118
|
json (~> 2.3)
|
|
108
|
-
language_server-protocol (
|
|
119
|
+
language_server-protocol (~> 3.17.0.2)
|
|
120
|
+
lint_roller (~> 1.1.0)
|
|
109
121
|
parallel (~> 1.10)
|
|
110
122
|
parser (>= 3.3.0.2)
|
|
111
123
|
rainbow (>= 2.2.2, < 4.0)
|
|
112
124
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
113
|
-
rubocop-ast (>= 1.
|
|
125
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
114
126
|
ruby-progressbar (~> 1.7)
|
|
115
127
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
116
|
-
rubocop-ast (1.
|
|
117
|
-
parser (>= 3.3.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
rubocop (~> 1.
|
|
122
|
-
rubocop-
|
|
123
|
-
|
|
124
|
-
rubocop
|
|
125
|
-
rubocop-
|
|
128
|
+
rubocop-ast (1.49.0)
|
|
129
|
+
parser (>= 3.3.7.2)
|
|
130
|
+
prism (~> 1.7)
|
|
131
|
+
rubocop-capybara (2.22.1)
|
|
132
|
+
lint_roller (~> 1.1)
|
|
133
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
134
|
+
rubocop-factory_bot (2.28.0)
|
|
135
|
+
lint_roller (~> 1.1)
|
|
136
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
137
|
+
rubocop-performance (1.26.1)
|
|
138
|
+
lint_roller (~> 1.1)
|
|
139
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
140
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
141
|
+
rubocop-rails (2.34.3)
|
|
126
142
|
activesupport (>= 4.2.0)
|
|
143
|
+
lint_roller (~> 1.1)
|
|
127
144
|
rack (>= 1.1)
|
|
128
|
-
rubocop (>= 1.
|
|
129
|
-
rubocop-ast (>= 1.
|
|
130
|
-
rubocop-rspec (3.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
145
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
146
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
147
|
+
rubocop-rspec (3.9.0)
|
|
148
|
+
lint_roller (~> 1.1)
|
|
149
|
+
rubocop (~> 1.81)
|
|
150
|
+
rubocop-rspec_rails (2.32.0)
|
|
151
|
+
lint_roller (~> 1.1)
|
|
152
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
153
|
+
rubocop-rspec (~> 3.5)
|
|
135
154
|
ruby-progressbar (1.13.0)
|
|
136
155
|
rumoji (0.5.0)
|
|
137
|
-
securerandom (0.
|
|
138
|
-
sqlite3 (
|
|
139
|
-
sqlite3 (
|
|
140
|
-
sqlite3 (
|
|
141
|
-
timeout (0.
|
|
156
|
+
securerandom (0.4.1)
|
|
157
|
+
sqlite3 (2.9.0-arm64-darwin)
|
|
158
|
+
sqlite3 (2.9.0-x86_64-darwin)
|
|
159
|
+
sqlite3 (2.9.0-x86_64-linux-gnu)
|
|
160
|
+
timeout (0.6.0)
|
|
142
161
|
tzinfo (2.0.6)
|
|
143
162
|
concurrent-ruby (~> 1.0)
|
|
144
|
-
unicode-display_width (3.
|
|
145
|
-
unicode-emoji (~> 4.
|
|
146
|
-
unicode-emoji (4.0
|
|
147
|
-
|
|
163
|
+
unicode-display_width (3.2.0)
|
|
164
|
+
unicode-emoji (~> 4.1)
|
|
165
|
+
unicode-emoji (4.2.0)
|
|
166
|
+
uri (1.1.1)
|
|
167
|
+
zeitwerk (2.7.4)
|
|
148
168
|
|
|
149
169
|
PLATFORMS
|
|
150
170
|
arm64-darwin-21
|
|
151
171
|
arm64-darwin-23
|
|
172
|
+
arm64-darwin-24
|
|
152
173
|
x86_64-darwin-21
|
|
153
174
|
x86_64-linux
|
|
154
175
|
|
|
@@ -160,7 +181,7 @@ DEPENDENCIES
|
|
|
160
181
|
rake (~> 13.0)
|
|
161
182
|
rspec (~> 3.9)
|
|
162
183
|
rubocop-gp!
|
|
163
|
-
sqlite3
|
|
184
|
+
sqlite3
|
|
164
185
|
|
|
165
186
|
BUNDLED WITH
|
|
166
187
|
2.3.15
|
data/README.md
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
You can visualize transitions map with [enum_machine-contrib](https://github.com/corp-gp/enum_machine-contrib)
|
|
6
6
|
|
|
7
|
-
## Why is `enum_machine` better
|
|
7
|
+
## Why is `enum_machine` better than [state_machines](https://github.com/state-machines/state_machines) / [aasm](https://github.com/aasm/aasm)?
|
|
8
8
|
|
|
9
9
|
- faster [5x](#Benchmarks)
|
|
10
10
|
- code lines: `enum_machine` - 348, `AASM` - 2139
|
|
11
11
|
- namespaced (via attr) by default: `order.state.to_collected`
|
|
12
|
-
- [aliases](
|
|
12
|
+
- [aliases](#aliases)
|
|
13
13
|
- guarantees of existing transitions
|
|
14
14
|
- simple run transitions with callbacks `order.update(state: "collected")` or `order.state.to_collected`
|
|
15
15
|
- `aasm` / `state_machines` **event driven**, `enum_machine` **state driven**
|
|
@@ -59,7 +59,7 @@ gem "enum_machine"
|
|
|
59
59
|
```ruby
|
|
60
60
|
# With ActiveRecord
|
|
61
61
|
class Product < ActiveRecord::Base
|
|
62
|
-
enum_machine :color, %w[red green]
|
|
62
|
+
enum_machine :color, %w[red green yellow]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
# Or with plain class
|
|
@@ -67,13 +67,15 @@ class Product
|
|
|
67
67
|
# attributes must be defined before including the EnumMachine module
|
|
68
68
|
attr_accessor :color
|
|
69
69
|
|
|
70
|
-
include EnumMachine[color: { enum: %w[red green] }]
|
|
70
|
+
include EnumMachine[color: { enum: %w[red green yellow] }]
|
|
71
71
|
# or reuse from model
|
|
72
72
|
Product::COLOR.enum_decorator
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
Product::COLOR.values # => ["red", "green"]
|
|
75
|
+
Product::COLOR.values # => ["red", "green", "yellow"]
|
|
76
76
|
Product::COLOR::RED # => "red"
|
|
77
|
+
Product::COLOR::RED.red? # => true
|
|
78
|
+
Product::COLOR::RED.human_name # => "Красный"
|
|
77
79
|
Product::COLOR::RED__GREEN # => ["red", "green"]
|
|
78
80
|
|
|
79
81
|
Product::COLOR["red"].red? # => true
|
|
@@ -83,6 +85,8 @@ product = Product.new
|
|
|
83
85
|
product.color # => nil
|
|
84
86
|
product.color = "red"
|
|
85
87
|
product.color.red? # => true
|
|
88
|
+
product.color.red__yellow? # => true
|
|
89
|
+
product.color.green__yellow? # => false
|
|
86
90
|
product.color.human_name # => "Красный"
|
|
87
91
|
```
|
|
88
92
|
|
|
@@ -166,7 +170,7 @@ product = Product.create(state: "created")
|
|
|
166
170
|
product.state.possible_transitions # => [nil, "approved"]
|
|
167
171
|
product.state.can_activated? # => false
|
|
168
172
|
product.state.to_activated! # => EnumMachine::Error: transition "created" => "activated" not defined in enum_machine
|
|
169
|
-
product.state.to_approved! # => true; equal to `product.update!(state: "
|
|
173
|
+
product.state.to_approved! # => true; equal to `product.update!(state: "approved")`
|
|
170
174
|
```
|
|
171
175
|
|
|
172
176
|
#### Skip transitions
|
|
@@ -223,7 +227,7 @@ product.color.human_name # => "Красный"
|
|
|
223
227
|
I18n scope can be changed with `i18n_scope` option:
|
|
224
228
|
|
|
225
229
|
```ruby
|
|
226
|
-
# For
|
|
230
|
+
# For ActiveRecord
|
|
227
231
|
class Product < ActiveRecord::Base
|
|
228
232
|
enum_machine :color, %w[red green], i18n_scope: "users.product"
|
|
229
233
|
end
|
|
@@ -234,6 +238,72 @@ class Product
|
|
|
234
238
|
end
|
|
235
239
|
```
|
|
236
240
|
|
|
241
|
+
### Standalone enum
|
|
242
|
+
|
|
243
|
+
`EnumMachine.enum` builds an enum class without a host attribute: for computed values,
|
|
244
|
+
virtual attributes, permissions, or constants shared across classes.
|
|
245
|
+
|
|
246
|
+
It provides constants, `values`, lookup `[]`, predicates (including combined `foo__bar?`),
|
|
247
|
+
I18n, and custom decorators:
|
|
248
|
+
|
|
249
|
+
```ruby
|
|
250
|
+
module ReviewTypeDecorator
|
|
251
|
+
def bonus_value
|
|
252
|
+
case self
|
|
253
|
+
when Comment::REVIEW_TYPE::VIDEO then 100
|
|
254
|
+
when Comment::REVIEW_TYPE::PHOTO then 50
|
|
255
|
+
else 10
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
class Comment < ActiveRecord::Base
|
|
261
|
+
REVIEW_TYPE = EnumMachine.enum(
|
|
262
|
+
%w[text photo video],
|
|
263
|
+
i18n_scope: "comment.review_type",
|
|
264
|
+
value_decorator: ReviewTypeDecorator,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
# computed, not a database column
|
|
268
|
+
def review_type
|
|
269
|
+
if video_ids.any?
|
|
270
|
+
REVIEW_TYPE::VIDEO
|
|
271
|
+
elsif photo_ids.any?
|
|
272
|
+
REVIEW_TYPE::PHOTO
|
|
273
|
+
else
|
|
274
|
+
REVIEW_TYPE::TEXT
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Constants and listing
|
|
280
|
+
Comment::REVIEW_TYPE.values # => ["text", "photo", "video"]
|
|
281
|
+
Comment::REVIEW_TYPE::VIDEO # => "video"
|
|
282
|
+
Comment::REVIEW_TYPE::PHOTO__VIDEO # => ["photo", "video"]
|
|
283
|
+
|
|
284
|
+
# Lookup by string or symbol
|
|
285
|
+
Comment::REVIEW_TYPE["video"] # => "video"
|
|
286
|
+
Comment::REVIEW_TYPE[:video] # => "video"
|
|
287
|
+
Comment::REVIEW_TYPE["unknown"] # => nil
|
|
288
|
+
|
|
289
|
+
# Decorator methods
|
|
290
|
+
Comment::REVIEW_TYPE::VIDEO.bonus_value # => 100
|
|
291
|
+
|
|
292
|
+
# Predicates on computed values
|
|
293
|
+
comment = Comment.new(video_ids: [1])
|
|
294
|
+
comment.review_type.video? # => true
|
|
295
|
+
comment.review_type.photo__video? # => true
|
|
296
|
+
comment.review_type.bonus_value # => 100
|
|
297
|
+
|
|
298
|
+
# Form helpers (when i18n_scope is set)
|
|
299
|
+
Comment::REVIEW_TYPE.values_for_form
|
|
300
|
+
# => [["Text", "text"], ["Photo", "photo"], ["Video", "video"]]
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
In `ActiveRecord` models, `enum_machine :attribute` relies on a database column for persistence
|
|
304
|
+
and dirty tracking. `EnumMachine.enum` is designed for everything else where you still want
|
|
305
|
+
enum capabilities without an underlying column.
|
|
306
|
+
|
|
237
307
|
## Benchmarks
|
|
238
308
|
[test/performance.rb](../master/test/performance.rb)
|
|
239
309
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/enum_machine/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "enum_machine"
|
|
7
|
+
spec.version = EnumMachine::VERSION
|
|
8
|
+
spec.authors = ["Ermolaev Andrey"]
|
|
9
|
+
spec.email = ["andruhafirst@yandex.ru"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "fast and siple usage state machine in your app"
|
|
12
|
+
spec.description = "Enum machine is a library for defining enums and setting state machines for attributes in ActiveRecord models and plain Ruby classes."
|
|
13
|
+
spec.homepage = "https://github.com/corp-gp/enum_machine"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/corp-gp/enum_machine"
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files =
|
|
25
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
spec.add_dependency "activemodel"
|
|
35
|
+
spec.add_dependency "activerecord"
|
|
36
|
+
spec.add_dependency "activesupport"
|
|
37
|
+
|
|
38
|
+
# For more information and examples about making a new gem, checkout our
|
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
40
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
41
|
+
end
|
|
@@ -19,8 +19,7 @@ module EnumMachine
|
|
|
19
19
|
klass.enum_machine(attr, enum_values, i18n_scope: i18n_scope)
|
|
20
20
|
else
|
|
21
21
|
enum_const_name = attr.to_s.upcase
|
|
22
|
-
|
|
23
|
-
enum_class = BuildEnumClass.call(enum_values: enum_values, i18n_scope: i18n_scope, value_class: value_class)
|
|
22
|
+
enum_class = EnumMachine.enum(enum_values, i18n_scope: i18n_scope, value_decorator: value_decorator)
|
|
24
23
|
|
|
25
24
|
define_methods =
|
|
26
25
|
Module.new do
|
data/lib/enum_machine/version.rb
CHANGED
data/lib/enum_machine.rb
CHANGED
|
@@ -29,6 +29,15 @@ module EnumMachine
|
|
|
29
29
|
def self.[](args)
|
|
30
30
|
DriverSimpleClass.call(args)
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
# Enum class without a host class: constants, `values`, `[]`, predicates and decorator
|
|
34
|
+
#
|
|
35
|
+
# COLOR = EnumMachine.enum(%w[red green], i18n_scope: "product.color", value_decorator: ColorDecorator)
|
|
36
|
+
# COLOR::RED.red? # => true
|
|
37
|
+
def self.enum(enum_values, i18n_scope: nil, value_decorator: nil)
|
|
38
|
+
value_class = BuildValueClass.call(enum_values: enum_values, i18n_scope: i18n_scope, value_decorator: value_decorator)
|
|
39
|
+
BuildEnumClass.call(enum_values: enum_values, i18n_scope: i18n_scope, value_class: value_class)
|
|
40
|
+
end
|
|
32
41
|
end
|
|
33
42
|
|
|
34
43
|
ActiveSupport.on_load(:active_record) do
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enum_machine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ermolaev Andrey
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activemodel
|
|
@@ -70,6 +69,7 @@ files:
|
|
|
70
69
|
- bin/console
|
|
71
70
|
- bin/setup
|
|
72
71
|
- docs/MIGRATING_FROM_RAILS_STRING_ENUM.ru.md
|
|
72
|
+
- enum_machine.gemspec
|
|
73
73
|
- lib/enum_machine.rb
|
|
74
74
|
- lib/enum_machine/attribute_persistence_methods.rb
|
|
75
75
|
- lib/enum_machine/build_enum_class.rb
|
|
@@ -86,7 +86,6 @@ metadata:
|
|
|
86
86
|
homepage_uri: https://github.com/corp-gp/enum_machine
|
|
87
87
|
source_code_uri: https://github.com/corp-gp/enum_machine
|
|
88
88
|
rubygems_mfa_required: 'true'
|
|
89
|
-
post_install_message:
|
|
90
89
|
rdoc_options: []
|
|
91
90
|
require_paths:
|
|
92
91
|
- lib
|
|
@@ -101,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
101
100
|
- !ruby/object:Gem::Version
|
|
102
101
|
version: '0'
|
|
103
102
|
requirements: []
|
|
104
|
-
rubygems_version: 3.
|
|
105
|
-
signing_key:
|
|
103
|
+
rubygems_version: 3.6.9
|
|
106
104
|
specification_version: 4
|
|
107
105
|
summary: fast and siple usage state machine in your app
|
|
108
106
|
test_files: []
|