enum_machine 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +6 -6
- data/lib/enum_machine/build_enum_class.rb +1 -1
- data/lib/enum_machine/build_value_class.rb +30 -35
- data/lib/enum_machine/machine.rb +1 -1
- data/lib/enum_machine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a93f18555b77dbf6370ff79f6e8a541a60f0b65e70a97673dca07c87ab6a83e8
|
4
|
+
data.tar.gz: 4bcf47330cc5492f55fe119d04a814caadfeb47becceb4e5bb9f408976255842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf9904e3c40b0a864ff4fde87a6e0b5c841b92c3279890ee15d18cf7191361f96a96dcf4ba67892b2f541f30072b8c677d8098b77965bb030f07a585ee46193
|
7
|
+
data.tar.gz: c93349f003295b86b1414765d2e844d3d7025c9d6b64da3e5a023eb86765bd627dc47a8c18a0d7ed7e636b9821ac596aee5c3e4d508c676fcdb2b79f406f3f46
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -73,7 +73,7 @@ GEM
|
|
73
73
|
zeitwerk (~> 2.6)
|
74
74
|
i18n (1.14.6)
|
75
75
|
concurrent-ruby (~> 1.0)
|
76
|
-
json (2.
|
76
|
+
json (2.9.0)
|
77
77
|
language_server-protocol (3.17.0.3)
|
78
78
|
logger (1.6.1)
|
79
79
|
method_source (1.1.0)
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
rack (3.1.8)
|
90
90
|
rainbow (3.1.1)
|
91
91
|
rake (13.2.1)
|
92
|
-
regexp_parser (2.9.
|
92
|
+
regexp_parser (2.9.3)
|
93
93
|
rspec (3.13.0)
|
94
94
|
rspec-core (~> 3.13.0)
|
95
95
|
rspec-expectations (~> 3.13.0)
|
@@ -103,17 +103,17 @@ GEM
|
|
103
103
|
diff-lcs (>= 1.2.0, < 2.0)
|
104
104
|
rspec-support (~> 3.13.0)
|
105
105
|
rspec-support (3.13.1)
|
106
|
-
rubocop (1.69.
|
106
|
+
rubocop (1.69.2)
|
107
107
|
json (~> 2.3)
|
108
108
|
language_server-protocol (>= 3.17.0)
|
109
109
|
parallel (~> 1.10)
|
110
110
|
parser (>= 3.3.0.2)
|
111
111
|
rainbow (>= 2.2.2, < 4.0)
|
112
|
-
regexp_parser (>= 2.
|
113
|
-
rubocop-ast (>= 1.36.
|
112
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
113
|
+
rubocop-ast (>= 1.36.2, < 2.0)
|
114
114
|
ruby-progressbar (~> 1.7)
|
115
115
|
unicode-display_width (>= 2.4.0, < 4.0)
|
116
|
-
rubocop-ast (1.
|
116
|
+
rubocop-ast (1.37.0)
|
117
117
|
parser (>= 3.3.1.0)
|
118
118
|
rubocop-capybara (2.21.0)
|
119
119
|
rubocop (~> 1.41)
|
@@ -20,7 +20,7 @@ module EnumMachine
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if i18n_scope
|
23
|
-
def self.values_for_form(specific_values = nil)
|
23
|
+
def self.values_for_form(specific_values = nil)
|
24
24
|
(specific_values || values).map { |v| [human_name_for(v), v] }
|
25
25
|
end
|
26
26
|
|
@@ -8,7 +8,9 @@ module EnumMachine
|
|
8
8
|
Class.new(String) do
|
9
9
|
include(value_decorator) if value_decorator
|
10
10
|
|
11
|
-
define_method(:machine) { machine }
|
11
|
+
define_method(:machine) { machine }
|
12
|
+
define_method(:enum_values) { enum_values }
|
13
|
+
private :enum_values, :machine
|
12
14
|
|
13
15
|
def inspect
|
14
16
|
"#<EnumMachine \"#{self}\">"
|
@@ -27,51 +29,44 @@ module EnumMachine
|
|
27
29
|
enum_values.each do |enum_value|
|
28
30
|
enum_name = enum_value.underscore
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# end
|
32
|
+
define_method(:"#{enum_name}?") do
|
33
|
+
self == enum_value
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
if machine&.transitions?
|
37
|
+
define_method(:"can_#{enum_name}?") do
|
38
|
+
possible_transitions.include?(enum_value)
|
37
39
|
end
|
38
|
-
|
40
|
+
end
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
aliases.each_key do |key|
|
44
|
+
define_method(:"#{key}?") do
|
45
|
+
machine.fetch_alias(key).include?(self)
|
46
|
+
end
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
if i18n_scope
|
50
|
+
full_scope = "enums.#{i18n_scope}"
|
51
|
+
define_method(:human_name) do
|
52
|
+
::I18n.t(self, scope: full_scope, default: self)
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
# def forming?
|
56
|
-
# machine.fetch_alias('forming').include?(self)
|
57
|
-
# end
|
56
|
+
def respond_to_missing?(method_name, _include_private = false)
|
57
|
+
method_name = method_name.name if method_name.is_a?(Symbol)
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
RUBY
|
59
|
+
method_name.end_with?("?") &&
|
60
|
+
method_name.include?("__") &&
|
61
|
+
(method_name.delete_suffix("?").split("__") - enum_values).empty?
|
63
62
|
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
# def human_name
|
68
|
-
# ::I18n.t(self, scope: "enums.product.state", default: self)
|
69
|
-
# end
|
64
|
+
def method_missing(method_name)
|
65
|
+
return super unless respond_to_missing?(method_name)
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
RUBY
|
67
|
+
m_enums = method_name.name.delete_suffix("?").split("__")
|
68
|
+
self.class.define_method(method_name) { m_enums.include?(self) }
|
69
|
+
send(method_name)
|
75
70
|
end
|
76
71
|
end
|
77
72
|
end
|
data/lib/enum_machine/machine.rb
CHANGED
@@ -4,7 +4,7 @@ module EnumMachine
|
|
4
4
|
class Machine
|
5
5
|
attr_reader :enum_values, :base_klass, :enum_const_name, :attr_name
|
6
6
|
|
7
|
-
def initialize(enum_values, base_klass = nil, enum_const_name = nil, attr_name = nil)
|
7
|
+
def initialize(enum_values, base_klass = nil, enum_const_name = nil, attr_name = nil)
|
8
8
|
@enum_values = enum_values
|
9
9
|
@base_klass = base_klass
|
10
10
|
@enum_const_name = enum_const_name
|
data/lib/enum_machine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ermolaev Andrey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|