active_record_compose 0.8.0 → 0.8.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 +5 -0
- data/UPGRADE.md +113 -0
- data/lib/active_record_compose/model.rb +15 -7
- data/lib/active_record_compose/transaction_support.rb +1 -1
- data/lib/active_record_compose/version.rb +1 -1
- data/lib/active_record_compose.rb +12 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1f795843fd29ef6dcd9cf17e897938ea97fc8f32db35f0b444b36455e619a3
|
4
|
+
data.tar.gz: 584e44a2c49c6861ad232f0c52c75b6d73abb550f39165fabe14690a71575c81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bc96e1479134c02ad09ae5d014ad5ad93c6d6ae6914a39724d42152f691120ccfaa76c681e3790bb1b436b49cc39d57eb8bfe7f6fc73d064818e22738ce1c9
|
7
|
+
data.tar.gz: e757a94164248e188c46413a706ec2418eb99c97f28bc5631305620c064b8fd7b04a6621d4809e405f95ac4d2228c22509700169f0049b581a1998ceba364acd
|
data/CHANGELOG.md
CHANGED
data/UPGRADE.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Migration Guide: `active_record_compose` 0.8.x to 0.9.0+
|
2
|
+
|
3
|
+
⚠️ **Breaking Change**
|
4
|
+
|
5
|
+
This guide explains how to migrate from version **0.8.x** to **0.9.0 or later**, assuming that your codebase includes:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
self.persisted_flag_callback_control = false
|
9
|
+
```
|
10
|
+
|
11
|
+
This setting was officially **deprecated** in 0.9.0 and is **no longer supported**. Migration is required to adopt the current default behavior.
|
12
|
+
|
13
|
+
## Background
|
14
|
+
|
15
|
+
In version **0.7.x**, the default value of `persisted_flag_callback_control` was `false`.
|
16
|
+
|
17
|
+
In **0.8.x**, the default was changed to `true`.
|
18
|
+
If you are still using `false` in your models, it means you have **explicitly overridden the default**, likely to preserve backward-compatible behavior.
|
19
|
+
|
20
|
+
This guide helps you safely migrate to the new behavior while preserving intended callback semantics.
|
21
|
+
|
22
|
+
## Goal of the Migration
|
23
|
+
|
24
|
+
- Remove any use of `persisted_flag_callback_control = false`
|
25
|
+
- Adjust callback definitions to align with the semantics of `#persisted?`
|
26
|
+
|
27
|
+
## Step 1 – Remove Deprecated Flag
|
28
|
+
|
29
|
+
Find and remove all instances of:
|
30
|
+
|
31
|
+
```diff
|
32
|
+
-self.persisted_flag_callback_control = false
|
33
|
+
```
|
34
|
+
|
35
|
+
## Step 2 – Understand Callback Behavior Changes
|
36
|
+
|
37
|
+
With `persisted_flag_callback_control = true`, whether a callback is fired depends on the return value of `#persisted?`, not the method used (`create` or `update`).
|
38
|
+
|
39
|
+
### When saving with `#update`:
|
40
|
+
|
41
|
+
If `persisted?` returns `false`, then:
|
42
|
+
|
43
|
+
- `before_update`
|
44
|
+
- `after_update`
|
45
|
+
- `around_update`
|
46
|
+
|
47
|
+
will **not** be triggered.
|
48
|
+
|
49
|
+
✅ Recommended fix:
|
50
|
+
|
51
|
+
If you don’t differentiate between creation and update phases, switch to `*_save` callbacks:
|
52
|
+
|
53
|
+
```diff
|
54
|
+
- before_update :track_change
|
55
|
+
+ before_save :track_change
|
56
|
+
```
|
57
|
+
|
58
|
+
### When saving with `#create`:
|
59
|
+
|
60
|
+
If `persisted?` returns `true`, then:
|
61
|
+
|
62
|
+
- `before_create`
|
63
|
+
- `after_create`
|
64
|
+
- `around_create`
|
65
|
+
|
66
|
+
will **not** be triggered.
|
67
|
+
|
68
|
+
✅ Recommended fix:
|
69
|
+
|
70
|
+
Again, prefer `*_save` if you're using shared logic across creation and update:
|
71
|
+
|
72
|
+
```diff
|
73
|
+
- after_create :send_notification
|
74
|
+
+ after_save :send_notification
|
75
|
+
```
|
76
|
+
|
77
|
+
## Step 3 – Override `#persisted?` if Needed
|
78
|
+
|
79
|
+
If your composed model wraps an ActiveRecord instance and delegates its persistence logic, be sure to override `#persisted?` to reflect the correct state:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class Foo < ActiveRecordCompose::Model
|
83
|
+
def initialize(bar = Bar.new)
|
84
|
+
super()
|
85
|
+
@bar = bar
|
86
|
+
end
|
87
|
+
|
88
|
+
def persisted? = bar.persisted?
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
attr_reader :bar
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
## Migration Checklist ✅
|
97
|
+
|
98
|
+
- [ ] All models now `persisted_flag_callback_control` omit it entirely
|
99
|
+
- [ ] All callback definitions have been reviewed and updated
|
100
|
+
- [ ] Any `*_create` or `*_update` callbacks have been replaced with `*_save` where applicable
|
101
|
+
- [ ] `#persisted?` is correctly overridden where needed
|
102
|
+
- [ ] All tests pass and expected callbacks are fired
|
103
|
+
|
104
|
+
## Why This Change?
|
105
|
+
|
106
|
+
By aligning callback behavior with `persisted?`, you gain:
|
107
|
+
|
108
|
+
- Clearer intent and semantics
|
109
|
+
- More accurate behavior when composing or wrapping persisted models
|
110
|
+
- Improved compatibility with Rails conventions
|
111
|
+
- Less surprising callback triggering
|
112
|
+
|
113
|
+
If you have questions or run into edge cases, feel free to [open an issue](https://github.com/hamajyotan/active_record_compose/issues) or start a discussion.
|
@@ -82,7 +82,8 @@ module ActiveRecordCompose
|
|
82
82
|
deprecator.warn(
|
83
83
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
84
84
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
85
|
-
'(Alternatively, exclude statements that set `false`)'
|
85
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
86
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
86
87
|
)
|
87
88
|
# steep:ignore:end
|
88
89
|
run_callbacks(:save) { save_models(bang: false) }
|
@@ -108,7 +109,8 @@ module ActiveRecordCompose
|
|
108
109
|
deprecator.warn(
|
109
110
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
110
111
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
111
|
-
'(Alternatively, exclude statements that set `false`)'
|
112
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
113
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
112
114
|
)
|
113
115
|
# steep:ignore:end
|
114
116
|
run_callbacks(:save) { save_models(bang: true) }
|
@@ -151,7 +153,8 @@ module ActiveRecordCompose
|
|
151
153
|
deprecator.warn(
|
152
154
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
153
155
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
154
|
-
'(Alternatively, exclude statements that set `false`)'
|
156
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
157
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
155
158
|
)
|
156
159
|
# steep:ignore:end
|
157
160
|
|
@@ -177,7 +180,8 @@ module ActiveRecordCompose
|
|
177
180
|
deprecator.warn(
|
178
181
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
179
182
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
180
|
-
'(Alternatively, exclude statements that set `false`)'
|
183
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
184
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
181
185
|
)
|
182
186
|
# steep:ignore:end
|
183
187
|
|
@@ -226,7 +230,8 @@ module ActiveRecordCompose
|
|
226
230
|
deprecator.warn(
|
227
231
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
228
232
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
229
|
-
'(Alternatively, exclude statements that set `false`)'
|
233
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
234
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
230
235
|
)
|
231
236
|
# steep:ignore:end
|
232
237
|
with_callbacks(context: :update) { save_models(bang: false) }
|
@@ -250,7 +255,8 @@ module ActiveRecordCompose
|
|
250
255
|
deprecator.warn(
|
251
256
|
'The behavior with `persisted_flag_callback_control` set to `false` will be removed in 0.9.0. ' \
|
252
257
|
'Use `self.persisted_flag_callback_control = true` set to `true`. ' \
|
253
|
-
'(Alternatively, exclude statements that set `false`)'
|
258
|
+
'(Alternatively, exclude statements that set `false`) ' \
|
259
|
+
'cf. https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md ',
|
254
260
|
)
|
255
261
|
# steep:ignore:end
|
256
262
|
with_callbacks(context: :update) { save_models(bang: true) }
|
@@ -293,12 +299,14 @@ module ActiveRecordCompose
|
|
293
299
|
|
294
300
|
def raise_on_save_error_message = 'Failed to save the model.'
|
295
301
|
|
302
|
+
# steep:ignore:start
|
296
303
|
def deprecator
|
297
304
|
if ActiveRecord.respond_to?(:deprecator)
|
298
|
-
ActiveRecord.deprecator
|
305
|
+
ActiveRecord.deprecator
|
299
306
|
else # for rails 7.0.x or lower
|
300
307
|
ActiveSupport::Deprecation
|
301
308
|
end
|
302
309
|
end
|
310
|
+
# steep:ignore:end
|
303
311
|
end
|
304
312
|
end
|
@@ -7,3 +7,15 @@ require_relative 'active_record_compose/model'
|
|
7
7
|
|
8
8
|
module ActiveRecordCompose
|
9
9
|
end
|
10
|
+
|
11
|
+
if ActiveRecordCompose::VERSION == '0.8.1'
|
12
|
+
unless ENV['ACTIVE_RECORD_COMPOSE_SILENCE_DEPRECATION'] # rubocop:disable Style/SoleNestedConditional
|
13
|
+
warn <<~WARN
|
14
|
+
|
15
|
+
[DEPRECATION] You are using active_record_compose version 0.8.1, which is deprecated.
|
16
|
+
Please upgrade to the latest version.
|
17
|
+
See: https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md
|
18
|
+
|
19
|
+
WARN
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hamajyotan
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -16,6 +16,9 @@ dependencies:
|
|
16
16
|
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '7.0'
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '8.1'
|
19
22
|
type: :runtime
|
20
23
|
prerelease: false
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -23,6 +26,9 @@ dependencies:
|
|
23
26
|
- - ">="
|
24
27
|
- !ruby/object:Gem::Version
|
25
28
|
version: '7.0'
|
29
|
+
- - "<"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '8.1'
|
26
32
|
description: activemodel form object pattern. it embraces multiple AR models and provides
|
27
33
|
a transparent interface as if they were a single model.
|
28
34
|
email:
|
@@ -36,6 +42,7 @@ files:
|
|
36
42
|
- CODE_OF_CONDUCT.md
|
37
43
|
- LICENSE.txt
|
38
44
|
- README.md
|
45
|
+
- UPGRADE.md
|
39
46
|
- lib/active_record_compose.rb
|
40
47
|
- lib/active_record_compose/composed_collection.rb
|
41
48
|
- lib/active_record_compose/delegate_attribute.rb
|
@@ -52,8 +59,17 @@ metadata:
|
|
52
59
|
homepage_uri: https://github.com/hamajyotan/active_record_compose
|
53
60
|
source_code_uri: https://github.com/hamajyotan/active_record_compose
|
54
61
|
changelog_uri: https://github.com/hamajyotan/active_record_compose/blob/main/CHANGELOG.md
|
55
|
-
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.8.
|
62
|
+
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.8.1
|
56
63
|
rubygems_mfa_required: 'true'
|
64
|
+
post_install_message: |2+
|
65
|
+
|
66
|
+
Notice: This version (0.8.1) is deprecated.
|
67
|
+
|
68
|
+
Please upgrade to the latest version of `active_record_compose` as soon as possible.
|
69
|
+
Future releases will not support this version.
|
70
|
+
|
71
|
+
See https://github.com/hamajyotan/active_record_compose/blob/v0.8.1/UPGRADE.md for migration steps.
|
72
|
+
|
57
73
|
rdoc_options: []
|
58
74
|
require_paths:
|
59
75
|
- lib
|
@@ -72,3 +88,4 @@ rubygems_version: 3.6.2
|
|
72
88
|
specification_version: 4
|
73
89
|
summary: activemodel form object pattern
|
74
90
|
test_files: []
|
91
|
+
...
|