enumancer 2.0.0 → 2.0.1
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/CHANGELOG.md +6 -0
- data/lib/enumancer/definition.rb +0 -6
- data/lib/enumancer/type.rb +1 -1
- data/readme.md +6 -3
- 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: 0cc96e923555340bf64c4f0e192f04bfd97bd979cb6f87b9a9276ab16fe6a90d
|
|
4
|
+
data.tar.gz: bc524139eb8af0bcb1b426995cd9613263fea06564b5e98ca9b00f4032503399
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fd6fee96eb996eb72255638a3dc1b2bdbf370b86216768f97de65b3d010f84061599a81d6e13a58967428884b2fc1bb0729ef1d64bee595b99c6c795c76ce81
|
|
7
|
+
data.tar.gz: 54c630ffa42b42dcad138c8b9677c4ceafcd99ca93a172bf8e9122ed67909ba6f510f492d408fa52b65796f14bbde8c018de87c9f13543476514f01c419c4c5b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
- Remove snake_case validation for variant and field names.
|
|
6
|
+
- Preserve camelCase, PascalCase, and acronyms in generated variant class names.
|
|
7
|
+
- Keep duplicate name, reserved method, and generated constant collision checks.
|
|
8
|
+
|
|
3
9
|
## 2.0.0
|
|
4
10
|
|
|
5
11
|
- Require Ruby 4.0 or newer.
|
data/lib/enumancer/definition.rb
CHANGED
|
@@ -21,9 +21,6 @@ module Enumancer
|
|
|
21
21
|
|
|
22
22
|
def variant(name, *values, **fields)
|
|
23
23
|
name = Names.normalize(name)
|
|
24
|
-
unless /\A[a-z][a-z0-9]*(?:_[a-z0-9]+)*\z/.match?(name.to_s)
|
|
25
|
-
raise DefinitionError, "Invalid variant name: #{name.inspect}"
|
|
26
|
-
end
|
|
27
24
|
raise DefinitionError, "Duplicate variant: #{name}" if @definitions.key?(name)
|
|
28
25
|
|
|
29
26
|
if @backed
|
|
@@ -36,9 +33,6 @@ module Enumancer
|
|
|
36
33
|
normalized = {}
|
|
37
34
|
fields.each do |field, constraint|
|
|
38
35
|
field = Names.normalize(field)
|
|
39
|
-
unless /\A[a-z][a-z0-9]*(?:_[a-z0-9]+)*\z/.match?(field.to_s)
|
|
40
|
-
raise DefinitionError, "Invalid field name: #{field.inspect}"
|
|
41
|
-
end
|
|
42
36
|
raise DefinitionError, "Duplicate field: #{field}" if normalized.key?(field)
|
|
43
37
|
|
|
44
38
|
unless constraint.is_a?(Module) || constraint.equal?(Self)
|
data/lib/enumancer/type.rb
CHANGED
|
@@ -78,7 +78,7 @@ module Enumancer
|
|
|
78
78
|
name = definition.name
|
|
79
79
|
raise DefinitionError, "Reserved variant name: #{name}" if respond_to?(name, true)
|
|
80
80
|
|
|
81
|
-
constant = name.to_s.split('_').map
|
|
81
|
+
constant = name.to_s.split('_').map { |part| part[0, 1].upcase + part[1..].to_s }.join
|
|
82
82
|
raise DefinitionError, "Duplicate variant constant: #{constant}" if const_defined?(constant, false)
|
|
83
83
|
|
|
84
84
|
fields = definition.fields.transform_values { |constraint| constraint.equal?(Self) ? self : constraint }.freeze
|
data/readme.md
CHANGED
|
@@ -40,9 +40,12 @@ Each variant has its own generated `Data` class, such as `Color::Red`.
|
|
|
40
40
|
Variants without fields return canonical frozen instances and store no payload
|
|
41
41
|
or tag fields in those instances. Plain enum instances have no `value` method.
|
|
42
42
|
|
|
43
|
-
Names can be symbols or strings
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
Names can be symbols or strings; there is no naming-style validation. Case is
|
|
44
|
+
preserved, including camelCase and PascalCase. Generated class constants uppercase
|
|
45
|
+
the first letter of each underscore-separated part: `lParen` becomes `LParen`,
|
|
46
|
+
and `http_error` becomes `HttpError`. Ruby's rules for generated methods and
|
|
47
|
+
constants still apply. Names that conflict with existing type or instance methods,
|
|
48
|
+
or produce duplicate class constants, are rejected during definition.
|
|
46
49
|
|
|
47
50
|
## Backed enums
|
|
48
51
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enumancer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Łasačka
|
|
@@ -33,7 +33,7 @@ licenses:
|
|
|
33
33
|
metadata:
|
|
34
34
|
changelog_uri: https://github.com/lasaczka/enumancer/blob/main/CHANGELOG.md
|
|
35
35
|
bug_tracker_uri: https://github.com/lasaczka/enumancer/issues
|
|
36
|
-
documentation_uri: https://rubydoc.info/gems/enumancer/2.0.
|
|
36
|
+
documentation_uri: https://rubydoc.info/gems/enumancer/2.0.1
|
|
37
37
|
rdoc_options: []
|
|
38
38
|
require_paths:
|
|
39
39
|
- lib
|