active_version 1.0.1 → 1.1.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: 4636e51affa996a3f7c8cd98f32e05d6d1892ffe2dc3a79b58edb17bde8619f4
4
- data.tar.gz: 42b4f546aeec443faf25d9d3b039ed515499f6b9284b520792afd4af711a721e
3
+ metadata.gz: 6b9a886b4b5c2fd7b75b33e9f8d06557da0e51d221bf2c5bee1b88a33a79894e
4
+ data.tar.gz: 170d8b76a41e56d68e7ae22d2316cfdfbd4f559c27784a8bfcc0fc2e4e8c713b
5
5
  SHA512:
6
- metadata.gz: b78b064c4a79a1d1ce1780de50e009116e2e0864c25323745f6596385d197d058cc7c4a08bc58f07a7ff7addc678415482d7011698f1114da920b3f282498cc0
7
- data.tar.gz: 3b35459213700a318435ea787706e6565dfa6c95e311fa7e0f3ef7ad39206f9330b465791cc074be818f1b045e60c154d6d188d1385a4aa54bb81cd0b9daef3f
6
+ metadata.gz: b3a6edf6a90368e5a2b65d20439a4b7b2496dc432e75f6ea6a4805b25ac84dfe24155680da924ec3a696ba004d40826382b6547d45ca0769e400c71e14d05eea
7
+ data.tar.gz: 30a796563f87edfd7b54e938d2a93b75381e1d494febf1ed51748fcb4d45058d24343f2267275bdf6462d63059bf0fa8ab7f44ef5ac0f8d27e31cea7c765faea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0 (2026-03-27)
4
+
5
+ - Added `audit_auditable_optional` configuration option to control polymorphic `belongs_to :auditable` optionality
6
+
3
7
  ## 1.0.1 (2026-03-11)
4
8
 
5
9
  - Fixed Rails 7.2 thread-local audited options handling in `with_audited_options`
data/README.md CHANGED
@@ -182,6 +182,8 @@ end
182
182
 
183
183
  ### Destination Audit Model Configuration (Preferred)
184
184
 
185
+ The gem defines `belongs_to :auditable` (or your configured column) once, with `optional: false` by default (see `config.audit_auditable_optional`). Set `config.audit_auditable_optional = true` if `auditable_id` is composite or synthetic so polymorphic `load` may not resolve even when columns are valid. Do not re-declare `belongs_to :auditable` in subclasses to tweak options, that can leave duplicate validators from Rails. For presence checks without relying on association load, validate `auditable_type` and `auditable_id` explicitly.
186
+
185
187
  ```ruby
186
188
  class PostAudit < ApplicationRecord
187
189
  include ActiveVersion::Audits::AuditRecord
@@ -135,7 +135,12 @@ module ActiveVersion
135
135
  # Set up polymorphic association only when conventional id/type columns exist.
136
136
  auditable_column = ActiveVersion.column_mapper.column_for(source_class, :audits, :auditable)
137
137
  if column_names.include?("#{auditable_column}_id") && column_names.include?("#{auditable_column}_type")
138
- send(:belongs_to, auditable_column, polymorphic: true)
138
+ send(
139
+ :belongs_to,
140
+ auditable_column,
141
+ polymorphic: true,
142
+ optional: ActiveVersion.config.audit_auditable_optional
143
+ )
139
144
  end
140
145
 
141
146
  # Set up user association (if configured)
@@ -26,6 +26,7 @@ module ActiveVersion
26
26
  attr_accessor :audit_version_column
27
27
  attr_accessor :audit_user_column
28
28
  attr_accessor :audit_auditable_column
29
+ attr_accessor :audit_auditable_optional
29
30
  attr_accessor :audit_associated_column
30
31
  attr_accessor :audit_remote_address_column
31
32
  attr_accessor :audit_request_uuid_column
@@ -64,6 +65,7 @@ module ActiveVersion
64
65
  @audit_version_column = :version
65
66
  @audit_user_column = :user_id
66
67
  @audit_auditable_column = :auditable
68
+ @audit_auditable_optional = false
67
69
  @audit_associated_column = :associated
68
70
  @audit_remote_address_column = :remote_address
69
71
  @audit_request_uuid_column = :request_uuid
@@ -1,3 +1,3 @@
1
1
  module ActiveVersion
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -31,6 +31,10 @@ ActiveVersion.configure do |config|
31
31
  config.audit_remote_address_column = :remote_address
32
32
  config.audit_request_uuid_column = :request_uuid
33
33
 
34
+ # Polymorphic belongs_to :auditable uses optional: false by default. Set true if
35
+ # auditable_id is composite / synthetic and Rails' must-exist validation is wrong for your app.
36
+ # config.audit_auditable_optional = true
37
+
34
38
  # Infrastructure note:
35
39
  # Connection routing / connection topology / partition lifecycle are application-owned.
36
40
  # ActiveVersion reads/writes using the active ActiveRecord connection.
@@ -21,6 +21,7 @@ module ActiveVersion
21
21
  attr_accessor audit_version_column: Symbol | String
22
22
  attr_accessor audit_user_column: Symbol | String
23
23
  attr_accessor audit_auditable_column: Symbol | String
24
+ attr_accessor audit_auditable_optional: bool
24
25
  attr_accessor audit_associated_column: Symbol | String
25
26
  attr_accessor audit_remote_address_column: Symbol | String
26
27
  attr_accessor audit_request_uuid_column: Symbol | String
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov