enum_errors_away 0.3.1 → 0.5.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: a042969d984fbb4972117e18c9a8f8d95b3cf83cd517ff8bfa52d2fd5356bdd2
4
- data.tar.gz: cce23409d8eafac9e6cd2a8230127ef6060644f81fc6bd7b5871bb15cfc2ddb4
3
+ metadata.gz: 4bac7b769e6b6d6aeb286b30984f2dac7beec851398af2d42c56d7e3d0713732
4
+ data.tar.gz: 16a6cdfc2c12c90036c06e13211f52bafdb2affb118dc0290bea1f4b97e9450f
5
5
  SHA512:
6
- metadata.gz: 6fd2754ab0fc90df56e0170f6b61f37083c7a9ccdb111acc831bcba1d5bf1a0e473ee2dd12114b2f651ba5d3b2c1f5895dc86833200e1248259450aa2c6394c4
7
- data.tar.gz: d12a7d77b11ad0644d1c65d4aa6b17773d4eef109d1f856af9f590574de7b2b3fd6a2b16d54d05481e4e2afc7f1f365b2403e2b22d44f65df7534508545e858c
6
+ metadata.gz: 3e26fbee663d16d10a873f113500ea350c0e7e2eeae9617061a95b0328beb5681e22b4a0b43bc38dc892b4b725e93d0c85d6b32e5f9cbd64e82d64ae96a14329
7
+ data.tar.gz: c35c6f3b21e959825493b99f5046f0520c4c5d70e987382f7857388389c175dbd2a060b07a2c086a5fce26b8d54949153f9155fb8e76d348fb7837d251bd3cfc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] - 2026-04-01
4
+
5
+ ### Fixed
6
+
7
+ - Handle PostgreSQL native enum columns correctly. When a column has `type: :enum` (created with `t.enum` in migrations), the gem now declares an attribute for it. Previously, the gem skipped all existing columns, but Rails 8 requires explicit attribute declarations for PostgreSQL native enum columns. (Fixes #1)
8
+
9
+ ## [0.4.0] - 2025-12-05
10
+
11
+ Change the way we define the fallback.
12
+ Declare attribute if there's no column for it.
13
+
3
14
  ## [0.3.1] - 2025-11-28
4
15
 
5
16
  ### Fixed
@@ -27,37 +27,38 @@ module EnumErrorsAway
27
27
  { name => values }
28
28
  end
29
29
 
30
- # Pre-declare attributes for enum names that don't exist as columns
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
- # @type var enum_name: Symbol | String
38
- attribute enum_name, :integer if !attribute_types.key?(enum_name_str) && !columns_hash.key?(enum_name_str)
37
+ # Only declare attribute if there's no column for it,
38
+ # OR if the column is a PostgreSQL native enum (type :enum)
39
+ column = columns_hash[enum_name_str]
40
+ next if column && column.type != :enum
41
+
42
+ # Determine attribute type from enum values:
43
+ # - If all values are integers (or array), use :integer
44
+ # - If any value is a string, use :string
45
+ attr_type = if enum_values.is_a?(Array)
46
+ :integer
47
+ elsif enum_values.is_a?(Hash) && enum_values.values.any? { |v| v.is_a?(String) }
48
+ :string
49
+ else
50
+ :integer
51
+ end
52
+
53
+ attribute enum_name, attr_type
39
54
  rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotEstablished
40
- # Ignore database errors during schema introspection
55
+ # Silently ignore database errors - the enum may fail later,
56
+ # but that's the expected behavior without this gem
41
57
  end
42
58
  end
43
59
 
44
60
  # Call the original enum method
45
- begin
46
- super(name, values, **options)
47
- rescue ArgumentError, RuntimeError => 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
61
+ super(name, values, **options)
61
62
  end
62
63
  # rubocop:enable Metrics/AbcSize
63
64
  # rubocop:enable Metrics/MethodLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EnumErrorsAway
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_errors_away
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.7.2
148
+ rubygems_version: 3.6.9
149
149
  specification_version: 4
150
150
  summary: Fix Rails 7.2+ enum migration failures
151
151
  test_files: []