enum_errors_away 0.3.0 → 0.4.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/CHANGELOG.md +11 -0
- data/lib/enum_errors_away/active_record_extension.rb +20 -21
- data/lib/enum_errors_away/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b399f229db92482813751b010f00f4e21eb0a82997e5f9e6c7356fa44c4ee56
|
|
4
|
+
data.tar.gz: b0d640513ae8d2c7a678da4d46271dfcc3ca2f83990731a4042257c8e2167a41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c49582d5796dec9b0c9644506bb678976adcd3d541e97f594afdb4ba0533c3a3ea67fbdfb8607aab65b6ca3ece85295c546d1e1764ab258af7227e7e863df9ff
|
|
7
|
+
data.tar.gz: 1464ddcb152dc952bdae1f216b263495969975729767e9d3622f18862a0e00c1ddbe29f344e93b127d9383949cb0351349c9edaf29091984baaa7346c5ab504d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2025-12-05
|
|
4
|
+
|
|
5
|
+
Change the way we define the fallback.
|
|
6
|
+
Declare attribute if there's no column for it.
|
|
7
|
+
|
|
8
|
+
## [0.3.1] - 2025-11-28
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Catch `RuntimeError` in addition to `ArgumentError` for enum attribute type errors. Rails 8 raises `RuntimeError` for undeclared enum attributes during schema loading, which was causing the first test run to fail.
|
|
13
|
+
|
|
3
14
|
## [0.3.0] - 2025-11-18
|
|
4
15
|
|
|
5
16
|
### Changed
|
|
@@ -27,37 +27,36 @@ module EnumErrorsAway
|
|
|
27
27
|
{ name => values }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
# Pre-declare attributes for enum names that don't
|
|
30
|
+
# Pre-declare attributes for enum names that don't have a database column.
|
|
31
|
+
# We check columns_hash to avoid overriding the column's type.
|
|
31
32
|
definitions.each do |enum_name, enum_values|
|
|
32
33
|
next if enum_name.nil? || enum_name.to_s.empty?
|
|
33
|
-
next if enum_values.nil?
|
|
34
34
|
|
|
35
35
|
begin
|
|
36
36
|
enum_name_str = enum_name.to_s
|
|
37
|
-
#
|
|
38
|
-
|
|
37
|
+
# Only declare attribute if there's no column for it
|
|
38
|
+
next if columns_hash.key?(enum_name_str)
|
|
39
|
+
|
|
40
|
+
# Determine attribute type from enum values:
|
|
41
|
+
# - If all values are integers (or array), use :integer
|
|
42
|
+
# - If any value is a string, use :string
|
|
43
|
+
attr_type = if enum_values.is_a?(Array)
|
|
44
|
+
:integer
|
|
45
|
+
elsif enum_values.is_a?(Hash) && enum_values.values.any? { |v| v.is_a?(String) }
|
|
46
|
+
:string
|
|
47
|
+
else
|
|
48
|
+
:integer
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
attribute enum_name, attr_type
|
|
39
52
|
rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotEstablished
|
|
40
|
-
#
|
|
53
|
+
# Silently ignore database errors - the enum may fail later,
|
|
54
|
+
# but that's the expected behavior without this gem
|
|
41
55
|
end
|
|
42
56
|
end
|
|
43
57
|
|
|
44
58
|
# Call the original enum method
|
|
45
|
-
|
|
46
|
-
super(name, values, **options)
|
|
47
|
-
rescue ArgumentError => e
|
|
48
|
-
raise e unless e.message.include?('Undeclared attribute type for enum')
|
|
49
|
-
|
|
50
|
-
# Fallback: declare missing attributes and retry
|
|
51
|
-
definitions.each do |enum_name, enum_values|
|
|
52
|
-
next if enum_name.nil? || enum_name.to_s.empty?
|
|
53
|
-
next if enum_values.nil?
|
|
54
|
-
|
|
55
|
-
enum_name_str = enum_name.to_s
|
|
56
|
-
# @type var enum_name: Symbol | String
|
|
57
|
-
attribute enum_name, :integer unless attribute_types.key?(enum_name_str)
|
|
58
|
-
end
|
|
59
|
-
super(name, values, **options)
|
|
60
|
-
end
|
|
59
|
+
super(name, values, **options)
|
|
61
60
|
end
|
|
62
61
|
# rubocop:enable Metrics/AbcSize
|
|
63
62
|
# rubocop:enable Metrics/MethodLength
|