activerecord-duplicator 0.4.0 → 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: 4139cd9d1fa3041e02e9c17a2cf97c5f435230955c63b4ed29453b685fb6a985
4
- data.tar.gz: 8acef30197ddd818ffc3e957bf7db58821e8ae8b34f848d72fdfd5f1713680f4
3
+ metadata.gz: 017f95574ff90a7fdae2b54b38fd5be60fd6afa33b53a3a59486e159031c9bd1
4
+ data.tar.gz: a06425a620bae40393fc97b555f0616a8b5bfc87d6e90806089480f4506d3bdf
5
5
  SHA512:
6
- metadata.gz: 22a435ec6ebc808da2a87bb20a4b19c82188c80ec73db48c39f33868f1729dc80775bae437f0b7e7b6d6dd86ae0e47862a72a3fb34e9e96d0c70ea50b5991bab
7
- data.tar.gz: 5a5978f8259fde2473f220e8b2a953d649ae9c5824502ecb9a4c15bbfbbb9af9b2ae6cd5e9ebe89c5d5ea4a5d8c4de29e7c4efabe2058455d0197965f84fae3e
6
+ metadata.gz: 6dd54a10072d5521a176d1d5957246e033a42a2671e220ffc718f53f6442c4d6329241d0ab41aa1cc852585c697a36666d629d9c5f60c03d5b7dede47f986a97
7
+ data.tar.gz: afc907dc6fb3026b820eb1273500c53f7d51f0bd8ea960092956f81108253faa3d4795473f1a137133cade12f24365a4f8fb8136ff5831a0196e1cc3526f4bad
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2026-07-07
4
+
5
+ ### Added
6
+
7
+ - `Session#mark_skip_id(klass, *ids)` and `HandlerApi#mark_skip_id` —
8
+ register specific ids as skipped without loading records. Equivalent to
9
+ calling `mark_skip` on each record but avoids the database round-trip
10
+ when the ids are already known. Composite primary key ids are passed as
11
+ Arrays.
12
+
3
13
  ## [0.4.0] - 2026-07-06
4
14
 
5
15
  ### Fixed
data/README.md CHANGED
@@ -97,6 +97,28 @@ working), but the default `bulk_insert` path becomes a no-op and any
97
97
  echoes the old id back unchanged. `mark_skip_class` only differs from
98
98
  per-record `mark_skip` in cost: no enumeration is needed to opt each row in.
99
99
 
100
+ ### Skipping by id without loading records (`mark_skip_id`)
101
+
102
+ When the ids to skip are already known (a foreign key column, a prior
103
+ pluck, a config constant), use `mark_skip_id` to register them directly
104
+ without issuing a `SELECT`:
105
+
106
+ ```ruby
107
+ duplicator.duplicate(old_post, associations: [:taggings]) do |session|
108
+ session.mark_skip_id(Tag, 1, 2, 3)
109
+ end
110
+ ```
111
+
112
+ For composite primary keys pass each id as an Array:
113
+
114
+ ```ruby
115
+ session.mark_skip_id(Item, [tenant_id, 10], [tenant_id, 11])
116
+ ```
117
+
118
+ `mark_skip_id` has the same effect as calling `mark_skip` on the
119
+ corresponding records: `fetch_new_id` returns the old id unchanged for
120
+ each registered id.
121
+
100
122
  ### Registering an id from outside (`store_new_id` / `fetch_new_id`)
101
123
 
102
124
  If you produce a duplicate yourself (for example a model with a uniqueness
@@ -19,6 +19,11 @@ module ActiveRecord
19
19
  @session.mark_skip(...)
20
20
  end
21
21
 
22
+ #: (Class, *untyped) -> void
23
+ def mark_skip_id(...)
24
+ @session.mark_skip_id(...)
25
+ end
26
+
22
27
  #: (*Class) -> void
23
28
  def mark_skip_class(...)
24
29
  @session.mark_skip_class(...)
@@ -61,6 +61,16 @@ module ActiveRecord
61
61
  end
62
62
  end
63
63
 
64
+ # Declare that the given ids of the given class must not be duplicated,
65
+ # without loading the records. Equivalent to calling mark_skip on each
66
+ # record but avoids the database round-trip when the ids are already
67
+ # known. Each id should have the same shape as the class's primary key
68
+ # (scalar for a single-column pk, Array for a composite pk).
69
+ #: (Class, *untyped) -> void
70
+ def mark_skip_id(klass, *ids)
71
+ ids.each { |id| store_new_id(klass, old_id: id, new_id: id) }
72
+ end
73
+
64
74
  # Class-wide equivalent of mark_skip: it is exactly as if every record of
65
75
  # each given class had been passed to mark_skip. Handlers still fire
66
76
  # (matching the mark_skip case where a handler for the class is invoked
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  class Duplicator
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -15,6 +15,9 @@ module ActiveRecord
15
15
  # : (*ActiveRecord::Base) -> void
16
16
  def mark_skip: (*ActiveRecord::Base) -> void
17
17
 
18
+ # : (Class, *untyped) -> void
19
+ def mark_skip_id: (Class, *untyped) -> void
20
+
18
21
  # : (*Class) -> void
19
22
  def mark_skip_class: (*Class) -> void
20
23
 
@@ -47,6 +47,14 @@ module ActiveRecord
47
47
  # : (*ActiveRecord::Base) -> void
48
48
  def mark_skip: (*ActiveRecord::Base) -> void
49
49
 
50
+ # Declare that the given ids of the given class must not be duplicated,
51
+ # without loading the records. Equivalent to calling mark_skip on each
52
+ # record but avoids the database round-trip when the ids are already
53
+ # known. Each id should have the same shape as the class's primary key
54
+ # (scalar for a single-column pk, Array for a composite pk).
55
+ # : (Class, *untyped) -> void
56
+ def mark_skip_id: (Class, *untyped) -> void
57
+
50
58
  # Class-wide equivalent of mark_skip: it is exactly as if every record of
51
59
  # each given class had been passed to mark_skip. Handlers still fire
52
60
  # (matching the mark_skip case where a handler for the class is invoked
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-duplicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SmartHR