enum_machine 2.0.1 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aee9e7e0ece2e73f55fdd9c7180c3babfc1b2bed804cb3475fb1867b0dba757d
4
- data.tar.gz: a9b418f9678c7567baf43d84ac427249580fd4bc976b616677ecb52c89b082ec
3
+ metadata.gz: 22866d6d5f37dd78718e7e5eb27dd0066450d8730b821ffb13977888009b6ddd
4
+ data.tar.gz: fc4c40aa5ea99a6d14143ebec78d2a40b2c8bce58d21ff5507b4d3d2ee67bcf1
5
5
  SHA512:
6
- metadata.gz: b09927e13245d01a177fbc80b38714021d8c74c2d28a9b3538a3290e7aeb9b298c409e0571fcd9f5db92ddf152eeab8d15edc153315bd75884efadfa77c7b1db
7
- data.tar.gz: 422c5c3de070e51c9314dab1fcb724fd20c3c256433026c32bae4288757438dd51cefe43236ff5256af1577a16a06f343276ea7d4d26f620d433e17e89b2a3f9
6
+ metadata.gz: 247ea0d77022905062d7688dd1153037517fa71521c15f51477f66e4f8d368cf008262c0095a1465b068b24da3262ed01334f787504dce9a65265839bffa2726
7
+ data.tar.gz: 969db73142c57fcf94f82fa6c1eca59c79310a6c6e0399961fbee835c5da8596802039d699657f306f07ac0f0e64ba5692cb4d3dee0f3d02359313cd61b07bc5
data/.rubocop.yml CHANGED
@@ -24,3 +24,6 @@ Gp/UnsafeYamlMarshal:
24
24
  Enabled: true
25
25
  Exclude:
26
26
  - spec/**/*.rb
27
+
28
+ Gp/OptArgParameters:
29
+ Enabled: false
data/Gemfile CHANGED
@@ -10,4 +10,4 @@ gem "pry", "~> 0.12"
10
10
  gem "rake", "~> 13.0"
11
11
  gem "rspec", "~> 3.9"
12
12
  gem "rubocop-gp", github: "corp-gp/rubocop-gp"
13
- gem "sqlite3", "~> 1.4"
13
+ gem "sqlite3"
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: 867f7e1351c3730897cacdc20ce2d727604de245
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.1)
25
+ enum_machine (2.2.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 (7.2.1)
34
- activesupport (= 7.2.1)
35
- activerecord (7.2.1)
36
- activemodel (= 7.2.1)
37
- activesupport (= 7.2.1)
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 (7.2.1)
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
- ast (2.4.2)
51
- base64 (0.2.0)
52
- bigdecimal (3.1.8)
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.4)
56
- connection_pool (2.4.1)
57
- diff-lcs (1.5.1)
58
- drb (2.2.1)
59
- dry-core (1.0.1)
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.1.0)
63
- dry-logic (1.5.0)
65
+ dry-inflector (1.3.0)
66
+ dry-logic (1.6.0)
67
+ bigdecimal
64
68
  concurrent-ruby (~> 1.0)
65
- dry-core (~> 1.0, < 2)
69
+ dry-core (~> 1.1)
66
70
  zeitwerk (~> 2.6)
67
- dry-types (1.7.2)
68
- bigdecimal (~> 3.0)
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.6)
78
+ i18n (1.14.8)
75
79
  concurrent-ruby (~> 1.0)
76
- json (2.8.2)
77
- language_server-protocol (3.17.0.3)
78
- logger (1.6.1)
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 (5.25.2)
81
- parallel (1.26.3)
82
- parser (3.3.6.0)
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
- pry (0.14.2)
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.1.8)
98
+ rack (3.2.4)
90
99
  rainbow (3.1.1)
91
- rake (13.2.1)
92
- regexp_parser (2.9.2)
93
- rspec (3.13.0)
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.1)
108
+ rspec-core (3.13.6)
98
109
  rspec-support (~> 3.13.0)
99
- rspec-expectations (3.13.3)
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.1)
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.1)
106
- rubocop (1.69.0)
116
+ rspec-support (3.13.6)
117
+ rubocop (1.82.1)
107
118
  json (~> 2.3)
108
- language_server-protocol (>= 3.17.0)
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
- regexp_parser (>= 2.4, < 3.0)
113
- rubocop-ast (>= 1.36.1, < 2.0)
124
+ regexp_parser (>= 2.9.3, < 3.0)
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.36.1)
117
- parser (>= 3.3.1.0)
118
- rubocop-capybara (2.21.0)
119
- rubocop (~> 1.41)
120
- rubocop-factory_bot (2.26.1)
121
- rubocop (~> 1.61)
122
- rubocop-performance (1.23.0)
123
- rubocop (>= 1.48.1, < 2.0)
124
- rubocop-ast (>= 1.31.1, < 2.0)
125
- rubocop-rails (2.27.0)
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.52.0, < 2.0)
129
- rubocop-ast (>= 1.31.1, < 2.0)
130
- rubocop-rspec (3.2.0)
131
- rubocop (~> 1.61)
132
- rubocop-rspec_rails (2.30.0)
133
- rubocop (~> 1.61)
134
- rubocop-rspec (~> 3, >= 3.0.1)
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.3.2)
138
- sqlite3 (1.7.3-arm64-darwin)
139
- sqlite3 (1.7.3-x86_64-darwin)
140
- sqlite3 (1.7.3-x86_64-linux)
141
- timeout (0.4.2)
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.1.2)
145
- unicode-emoji (~> 4.0, >= 4.0.4)
146
- unicode-emoji (4.0.4)
147
- zeitwerk (2.6.18)
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 (~> 1.4)
184
+ sqlite3
164
185
 
165
186
  BUNDLED WITH
166
187
  2.3.15
data/README.md CHANGED
@@ -74,6 +74,8 @@ end
74
74
 
75
75
  Product::COLOR.values # => ["red", "green"]
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
@@ -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) # rubocop:disable Gp/OptArgParameters
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
 
@@ -36,7 +36,7 @@ module EnumMachine
36
36
  end
37
37
 
38
38
  enum_values.each do |enum_value|
39
- const_set enum_value.underscore.upcase, enum_value.to_s.freeze
39
+ const_set enum_value.underscore.upcase, value_class.new(enum_value).freeze
40
40
  end
41
41
 
42
42
  aliases.each_key do |key|
@@ -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 } if 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
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
31
- # def active?
32
- # self == 'active'
33
- # end
32
+ define_method(:"#{enum_name}?") do
33
+ self == enum_value
34
+ end
34
35
 
35
- def #{enum_name}?
36
- self == '#{enum_value}'
36
+ if machine&.transitions?
37
+ define_method(:"can_#{enum_name}?") do
38
+ possible_transitions.include?(enum_value)
37
39
  end
38
- RUBY
40
+ end
41
+ end
39
42
 
40
- if machine&.transitions?
41
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
42
- # def can_active?
43
- # possible_transitions.include?('canceled')
44
- # end
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
- def can_#{enum_name}?
47
- possible_transitions.include?('#{enum_value}')
48
- end
49
- RUBY
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
- aliases.each_key do |key|
54
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
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
- def #{key}?
60
- machine.fetch_alias('#{key}').include?(self)
61
- end
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
- if i18n_scope
66
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
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
- def human_name
72
- ::I18n.t(self, scope: "enums.#{i18n_scope}", default: self)
73
- end
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
@@ -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) # rubocop:disable Gp/OptArgParameters
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EnumMachine
4
- VERSION = "2.0.1"
4
+ VERSION = "2.2.0"
5
5
  end
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.0.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ermolaev Andrey
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activemodel
@@ -86,7 +85,6 @@ metadata:
86
85
  homepage_uri: https://github.com/corp-gp/enum_machine
87
86
  source_code_uri: https://github.com/corp-gp/enum_machine
88
87
  rubygems_mfa_required: 'true'
89
- post_install_message:
90
88
  rdoc_options: []
91
89
  require_paths:
92
90
  - lib
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
103
101
  requirements: []
104
- rubygems_version: 3.3.17
105
- signing_key:
102
+ rubygems_version: 3.6.9
106
103
  specification_version: 4
107
104
  summary: fast and siple usage state machine in your app
108
105
  test_files: []