paper_trail_diff 0.16.0 → 0.17.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 +581 -1
- data/README.md +42 -7
- data/docs/architecture.md +7 -5
- data/docs/performance.md +86 -38
- data/docs/reference.md +309 -92
- data/docs/testing.md +240 -32
- data/lib/paper_trail_diff/activity_belongs_to_event_applier.rb +2 -16
- data/lib/paper_trail_diff/activity_boundary.rb +55 -34
- data/lib/paper_trail_diff/activity_child_candidate_loader.rb +46 -57
- data/lib/paper_trail_diff/activity_collection_event_applier.rb +3 -13
- data/lib/paper_trail_diff/activity_collection_route_updater.rb +1 -1
- data/lib/paper_trail_diff/activity_event.rb +33 -21
- data/lib/paper_trail_diff/activity_event_record_resolver.rb +16 -116
- data/lib/paper_trail_diff/activity_event_route_finder.rb +29 -29
- data/lib/paper_trail_diff/activity_event_snapshot_refresher.rb +2 -7
- data/lib/paper_trail_diff/activity_history.rb +90 -49
- data/lib/paper_trail_diff/activity_range.rb +9 -35
- data/lib/paper_trail_diff/activity_root_snapshot_refresher.rb +74 -40
- data/lib/paper_trail_diff/activity_root_steps.rb +10 -13
- data/lib/paper_trail_diff/activity_scope_filter.rb +77 -0
- data/lib/paper_trail_diff/activity_snapshot_delta.rb +12 -15
- data/lib/paper_trail_diff/activity_snapshot_sequence.rb +37 -15
- data/lib/paper_trail_diff/activity_target_candidate_loader.rb +35 -43
- data/lib/paper_trail_diff/activity_timeline_builder.rb +194 -249
- data/lib/paper_trail_diff/activity_transaction_grouper.rb +3 -1
- data/lib/paper_trail_diff/activity_tree_filter.rb +54 -13
- data/lib/paper_trail_diff/activity_version_collector.rb +72 -138
- data/lib/paper_trail_diff/activity_view.rb +22 -11
- data/lib/paper_trail_diff/analysis.rb +19 -5
- data/lib/paper_trail_diff/analysis_batch.rb +16 -58
- data/lib/paper_trail_diff/approximate_paths.rb +4 -8
- data/lib/paper_trail_diff/association_activity_edge.rb +5 -24
- data/lib/paper_trail_diff/association_activity_selection.rb +10 -18
- data/lib/paper_trail_diff/association_discovery.rb +1 -6
- data/lib/paper_trail_diff/association_key.rb +9 -6
- data/lib/paper_trail_diff/association_traversal.rb +49 -6
- data/lib/paper_trail_diff/batch_boundary_resolver.rb +33 -42
- data/lib/paper_trail_diff/batch_preload.rb +2 -12
- data/lib/paper_trail_diff/batched_root_analyses.rb +72 -0
- data/lib/paper_trail_diff/batched_root_analyzer.rb +16 -14
- data/lib/paper_trail_diff/batched_root_versions.rb +25 -20
- data/lib/paper_trail_diff/branch_snapshot_refresher.rb +27 -31
- data/lib/paper_trail_diff/change_attribution.rb +329 -0
- data/lib/paper_trail_diff/change_row.rb +30 -10
- data/lib/paper_trail_diff/comparison_batch.rb +3 -4
- data/lib/paper_trail_diff/configuration.rb +1 -1
- data/lib/paper_trail_diff/deleted_analysis_batch.rb +22 -37
- data/lib/paper_trail_diff/deleted_root_filter.rb +3 -6
- data/lib/paper_trail_diff/deprecation.rb +4 -43
- data/lib/paper_trail_diff/diagnostics.rb +1 -2
- data/lib/paper_trail_diff/direct_record_state_loader.rb +8 -1
- data/lib/paper_trail_diff/endpoint.rb +78 -44
- data/lib/paper_trail_diff/errors.rb +2 -9
- data/lib/paper_trail_diff/fallback_paths.rb +2 -5
- data/lib/paper_trail_diff/habtm_transaction_owners.rb +5 -3
- data/lib/paper_trail_diff/historical_association_reifier.rb +3 -1
- data/lib/paper_trail_diff/historical_filter.rb +40 -15
- data/lib/paper_trail_diff/historical_snapshot_store.rb +80 -38
- data/lib/paper_trail_diff/instrumentation.rb +0 -8
- data/lib/paper_trail_diff/live_endpoint_batch_loader.rb +11 -7
- data/lib/paper_trail_diff/live_endpoint_provider.rb +7 -23
- data/lib/paper_trail_diff/live_graph_collector.rb +3 -3
- data/lib/paper_trail_diff/nested_comparator.rb +46 -19
- data/lib/paper_trail_diff/net_change.rb +276 -0
- data/lib/paper_trail_diff/own_window.rb +35 -0
- data/lib/paper_trail_diff/paper_trail_adapter.rb +40 -45
- data/lib/paper_trail_diff/prepared_activity_index.rb +197 -45
- data/lib/paper_trail_diff/prepared_child_candidates.rb +58 -0
- data/lib/paper_trail_diff/prepared_edge_loader.rb +43 -107
- data/lib/paper_trail_diff/prepared_history.rb +20 -31
- data/lib/paper_trail_diff/prepared_history_loader.rb +46 -9
- data/lib/paper_trail_diff/prepared_record_index.rb +137 -47
- data/lib/paper_trail_diff/prepared_snapshot_builder.rb +16 -0
- data/lib/paper_trail_diff/prepared_state_association_reader.rb +17 -19
- data/lib/paper_trail_diff/read_snapshot.rb +41 -19
- data/lib/paper_trail_diff/recorded_changes.rb +10 -11
- data/lib/paper_trail_diff/recorded_changes_reader.rb +60 -0
- data/lib/paper_trail_diff/recorded_class.rb +14 -19
- data/lib/paper_trail_diff/recorded_columns.rb +33 -0
- data/lib/paper_trail_diff/root_version_plan.rb +20 -22
- data/lib/paper_trail_diff/root_version_selection.rb +39 -29
- data/lib/paper_trail_diff/scope_condition.rb +7 -17
- data/lib/paper_trail_diff/scope_ranking.rb +16 -22
- data/lib/paper_trail_diff/scoped_analysis.rb +27 -4
- data/lib/paper_trail_diff/scoped_analysis_builder.rb +4 -3
- data/lib/paper_trail_diff/scoped_root_selection.rb +60 -41
- data/lib/paper_trail_diff/snapshot_normalizer.rb +18 -3
- data/lib/paper_trail_diff/stored_json_values.rb +52 -0
- data/lib/paper_trail_diff/stored_time_precision.rb +30 -18
- data/lib/paper_trail_diff/stored_values.rb +20 -0
- data/lib/paper_trail_diff/support.rb +185 -35
- data/lib/paper_trail_diff/time_of_day.rb +39 -0
- data/lib/paper_trail_diff/time_range.rb +37 -20
- data/lib/paper_trail_diff/time_version_range.rb +5 -10
- data/lib/paper_trail_diff/timeline_builder.rb +3 -3
- data/lib/paper_trail_diff/timeline_range.rb +18 -12
- data/lib/paper_trail_diff/timeline_snapshot_provider.rb +1 -1
- data/lib/paper_trail_diff/total_order.rb +55 -0
- data/lib/paper_trail_diff/transaction_cut.rb +192 -91
- data/lib/paper_trail_diff/traversal_preparer.rb +5 -8
- data/lib/paper_trail_diff/value_objects.rb +8 -4
- data/lib/paper_trail_diff/version.rb +1 -1
- data/lib/paper_trail_diff/version_association_candidate_scope.rb +27 -16
- data/lib/paper_trail_diff/version_boundary.rb +37 -21
- data/lib/paper_trail_diff/version_query.rb +25 -25
- data/lib/paper_trail_diff/version_range.rb +12 -16
- data/lib/paper_trail_diff/version_sequence_diagnostics.rb +32 -0
- data/lib/paper_trail_diff/version_table.rb +12 -8
- data/lib/paper_trail_diff.rb +28 -42
- data/sig/generated/paper_trail_diff/activity_belongs_to_event_applier.rbs +0 -8
- data/sig/generated/paper_trail_diff/activity_boundary.rbs +39 -17
- data/sig/generated/paper_trail_diff/activity_child_candidate_loader.rbs +19 -22
- data/sig/generated/paper_trail_diff/activity_collection_event_applier.rbs +0 -5
- data/sig/generated/paper_trail_diff/activity_event.rbs +25 -9
- data/sig/generated/paper_trail_diff/activity_event_record_resolver.rbs +6 -34
- data/sig/generated/paper_trail_diff/activity_event_route_finder.rbs +11 -4
- data/sig/generated/paper_trail_diff/activity_event_snapshot_refresher.rbs +0 -3
- data/sig/generated/paper_trail_diff/activity_history.rbs +54 -19
- data/sig/generated/paper_trail_diff/activity_range.rbs +6 -20
- data/sig/generated/paper_trail_diff/activity_root_snapshot_refresher.rbs +36 -2
- data/sig/generated/paper_trail_diff/activity_root_steps.rbs +6 -6
- data/sig/generated/paper_trail_diff/activity_scope_filter.rbs +51 -0
- data/sig/generated/paper_trail_diff/activity_snapshot_delta.rbs +5 -3
- data/sig/generated/paper_trail_diff/activity_snapshot_sequence.rbs +21 -3
- data/sig/generated/paper_trail_diff/activity_target_candidate_loader.rbs +19 -24
- data/sig/generated/paper_trail_diff/activity_timeline_builder.rbs +121 -127
- data/sig/generated/paper_trail_diff/activity_tree_filter.rbs +41 -8
- data/sig/generated/paper_trail_diff/activity_version_collector.rbs +42 -35
- data/sig/generated/paper_trail_diff/activity_view.rbs +16 -8
- data/sig/generated/paper_trail_diff/analysis.rbs +15 -6
- data/sig/generated/paper_trail_diff/analysis_batch.rbs +6 -24
- data/sig/generated/paper_trail_diff/association_activity_edge.rbs +0 -13
- data/sig/generated/paper_trail_diff/association_activity_selection.rbs +6 -9
- data/sig/generated/paper_trail_diff/association_discovery.rbs +0 -3
- data/sig/generated/paper_trail_diff/association_key.rbs +5 -0
- data/sig/generated/paper_trail_diff/association_traversal.rbs +26 -2
- data/sig/generated/paper_trail_diff/batch_boundary_resolver.rbs +17 -17
- data/sig/generated/paper_trail_diff/batch_preload.rbs +0 -4
- data/sig/generated/paper_trail_diff/batched_root_analyses.rbs +47 -0
- data/sig/generated/paper_trail_diff/batched_root_analyzer.rbs +9 -8
- data/sig/generated/paper_trail_diff/batched_root_versions.rbs +10 -6
- data/sig/generated/paper_trail_diff/branch_snapshot_refresher.rbs +11 -5
- data/sig/generated/paper_trail_diff/change_attribution.rbs +194 -0
- data/sig/generated/paper_trail_diff/change_row.rbs +22 -7
- data/sig/generated/paper_trail_diff/deleted_analysis_batch.rbs +11 -12
- data/sig/generated/paper_trail_diff/deleted_root_filter.rbs +0 -2
- data/sig/generated/paper_trail_diff/deprecation.rbs +4 -24
- data/sig/generated/paper_trail_diff/direct_record_state_loader.rbs +4 -0
- data/sig/generated/paper_trail_diff/endpoint.rbs +40 -16
- data/sig/generated/paper_trail_diff/errors.rbs +2 -11
- data/sig/generated/paper_trail_diff/habtm_transaction_owners.rbs +2 -1
- data/sig/generated/paper_trail_diff/historical_filter.rbs +20 -9
- data/sig/generated/paper_trail_diff/historical_snapshot_store.rbs +40 -10
- data/sig/generated/paper_trail_diff/instrumentation.rbs +0 -3
- data/sig/generated/paper_trail_diff/live_endpoint_batch_loader.rbs +3 -0
- data/sig/generated/paper_trail_diff/live_endpoint_provider.rbs +5 -8
- data/sig/generated/paper_trail_diff/live_graph_collector.rbs +2 -2
- data/sig/generated/paper_trail_diff/nested_comparator.rbs +20 -4
- data/sig/generated/paper_trail_diff/net_change.rbs +168 -0
- data/sig/generated/paper_trail_diff/own_window.rbs +22 -0
- data/sig/generated/paper_trail_diff/paper_trail_adapter.rbs +9 -6
- data/sig/generated/paper_trail_diff/prepared_activity_index.rbs +114 -14
- data/sig/generated/paper_trail_diff/prepared_child_candidates.rbs +39 -0
- data/sig/generated/paper_trail_diff/prepared_edge_loader.rbs +18 -35
- data/sig/generated/paper_trail_diff/prepared_history.rbs +9 -12
- data/sig/generated/paper_trail_diff/prepared_history_loader.rbs +28 -3
- data/sig/generated/paper_trail_diff/prepared_record_index.rbs +68 -14
- data/sig/generated/paper_trail_diff/prepared_snapshot_builder.rbs +12 -0
- data/sig/generated/paper_trail_diff/prepared_state_association_reader.rbs +6 -7
- data/sig/generated/paper_trail_diff/read_snapshot.rbs +27 -8
- data/sig/generated/paper_trail_diff/recorded_changes.rbs +4 -2
- data/sig/generated/paper_trail_diff/recorded_changes_reader.rbs +41 -0
- data/sig/generated/paper_trail_diff/recorded_class.rbs +7 -6
- data/sig/generated/paper_trail_diff/recorded_columns.rbs +21 -0
- data/sig/generated/paper_trail_diff/root_version_plan.rbs +8 -4
- data/sig/generated/paper_trail_diff/root_version_selection.rbs +27 -13
- data/sig/generated/paper_trail_diff/scope_condition.rbs +0 -2
- data/sig/generated/paper_trail_diff/scope_ranking.rbs +10 -10
- data/sig/generated/paper_trail_diff/scoped_analysis.rbs +19 -0
- data/sig/generated/paper_trail_diff/scoped_analysis_builder.rbs +2 -2
- data/sig/generated/paper_trail_diff/scoped_root_selection.rbs +37 -14
- data/sig/generated/paper_trail_diff/snapshot_normalizer.rbs +7 -0
- data/sig/generated/paper_trail_diff/stored_json_values.rbs +35 -0
- data/sig/generated/paper_trail_diff/stored_time_precision.rbs +19 -5
- data/sig/generated/paper_trail_diff/stored_values.rbs +13 -0
- data/sig/generated/paper_trail_diff/support.rbs +120 -23
- data/sig/generated/paper_trail_diff/time_of_day.rbs +21 -0
- data/sig/generated/paper_trail_diff/time_range.rbs +15 -8
- data/sig/generated/paper_trail_diff/time_version_range.rbs +2 -5
- data/sig/generated/paper_trail_diff/timeline_builder.rbs +2 -2
- data/sig/generated/paper_trail_diff/timeline_range.rbs +12 -7
- data/sig/generated/paper_trail_diff/total_order.rbs +32 -0
- data/sig/generated/paper_trail_diff/transaction_cut.rbs +111 -52
- data/sig/generated/paper_trail_diff/traversal_preparer.rbs +2 -2
- data/sig/generated/paper_trail_diff/value_objects.rbs +5 -1
- data/sig/generated/paper_trail_diff/version_association_candidate_scope.rbs +10 -9
- data/sig/generated/paper_trail_diff/version_boundary.rbs +15 -8
- data/sig/generated/paper_trail_diff/version_query.rbs +17 -10
- data/sig/generated/paper_trail_diff/version_range.rbs +6 -9
- data/sig/generated/paper_trail_diff/version_sequence_diagnostics.rbs +13 -0
- data/sig/generated/paper_trail_diff/version_table.rbs +3 -0
- data/sig/generated/paper_trail_diff.rbs +16 -16
- metadata +28 -6
- data/lib/paper_trail_diff/preloaded_endpoint_batch_loader.rb +0 -60
- data/sig/generated/paper_trail_diff/preloaded_endpoint_batch_loader.rbs +0 -32
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
module PaperTrailDiff
|
|
5
5
|
# Places one version relative to another on the recorded timeline.
|
|
6
6
|
module VersionBoundary
|
|
7
|
-
|
|
7
|
+
@transactional = {} #: Hash[untyped, bool]
|
|
8
|
+
@version_records = {} #: Hash[untyped, bool]
|
|
8
9
|
|
|
9
10
|
# Whether `candidate` was recorded at or after `boundary`. Versions sharing
|
|
10
11
|
# a timestamp are ordered by id, which reflects insertion order only for
|
|
11
12
|
# sequential ids in one version table; any other tie cannot be ordered, and
|
|
12
13
|
# guessing would place a change on an arbitrary side of the boundary. A
|
|
13
14
|
# bare instant has no position among same-time versions, so it keeps them.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
# `time` and `boundary_time` are when each was recorded, which a caller
|
|
16
|
+
# placing many versions against one boundary reads once.
|
|
17
|
+
#: (untyped, untyped, ?time: untyped, ?boundary_time: untyped) -> bool
|
|
18
|
+
def self.at_or_after?(candidate, boundary, time: candidate.created_at,
|
|
19
|
+
boundary_time: boundary.created_at)
|
|
20
|
+
return time > boundary_time unless time == boundary_time
|
|
18
21
|
return true unless version_record?(boundary)
|
|
19
22
|
return true if same_version?(candidate, boundary)
|
|
20
23
|
|
|
@@ -22,7 +25,8 @@ module PaperTrailDiff
|
|
|
22
25
|
raise AmbiguousVersionOrderError, Support.ambiguous_message([boundary, candidate])
|
|
23
26
|
end
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
# Different rows of one table, so one id comes after the other.
|
|
29
|
+
Support.compare_versions(candidate, boundary).positive?
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
# A range starting at a version starts before that version's transaction,
|
|
@@ -31,25 +35,25 @@ module PaperTrailDiff
|
|
|
31
35
|
# version, can be recorded before the start, so the start moves back to
|
|
32
36
|
# the earliest version of each root's first transaction in the range.
|
|
33
37
|
# History loaded from the start alone would read that child after its
|
|
34
|
-
# change.
|
|
38
|
+
# change. The transactions go 500 to a statement.
|
|
35
39
|
#: (Array[untyped], untyped) -> untyped
|
|
36
|
-
def transaction_start(root_versions, start_at)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
def self.transaction_start(root_versions, start_at)
|
|
41
|
+
earliest = opening_transactions(root_versions, start_at)
|
|
42
|
+
.each_slice(Support::IDS_PER_STATEMENT).filter_map do |slice|
|
|
43
|
+
root_versions.first.class.where(transaction_id: slice).minimum(:created_at)
|
|
44
|
+
end.min
|
|
41
45
|
earliest && earliest < start_at ? earliest : start_at
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
# The transaction of each root's first version at or after the start.
|
|
45
49
|
#: (Array[untyped], untyped) -> Array[untyped]
|
|
46
|
-
def opening_transactions(root_versions, start_at)
|
|
50
|
+
def self.opening_transactions(root_versions, start_at)
|
|
47
51
|
return [] unless start_at
|
|
48
52
|
|
|
49
53
|
root_versions.reject { |version| version.created_at < start_at }
|
|
50
54
|
.sort_by { |version| Support.chronological_version_key(version) }
|
|
51
|
-
.uniq { |version|
|
|
52
|
-
.filter_map { |version| transaction_id(version) }
|
|
55
|
+
.uniq { |version| Endpoint.identity(version) }
|
|
56
|
+
.filter_map { |version| transaction_id(version) }
|
|
53
57
|
end
|
|
54
58
|
private_class_method :opening_transactions
|
|
55
59
|
|
|
@@ -57,21 +61,33 @@ module PaperTrailDiff
|
|
|
57
61
|
# it nil outside a transaction. Both read as "no transaction here", which
|
|
58
62
|
# groups with nothing.
|
|
59
63
|
#: (untyped) -> untyped
|
|
60
|
-
def transaction_id(version)
|
|
61
|
-
version.transaction_id if
|
|
64
|
+
def self.transaction_id(version)
|
|
65
|
+
version.transaction_id if transactional?(version)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Answered once for each Active Record class (see Support.per_model).
|
|
69
|
+
#: (untyped) -> bool
|
|
70
|
+
def self.transactional?(version)
|
|
71
|
+
known = @transactional #: Hash[untyped, bool]
|
|
72
|
+
Support.per_model(known, version) { |value| value.respond_to?(:transaction_id) }
|
|
62
73
|
end
|
|
74
|
+
private_class_method :transactional?
|
|
63
75
|
|
|
76
|
+
# Answered once for each Active Record class, as `transactional?` is.
|
|
64
77
|
#: (untyped) -> bool
|
|
65
|
-
def version_record?(value)
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
def self.version_record?(value)
|
|
79
|
+
known = @version_records #: Hash[untyped, bool]
|
|
80
|
+
Support.per_model(known, value) do |candidate|
|
|
81
|
+
candidate.respond_to?(:id) && candidate.respond_to?(:item_type) &&
|
|
82
|
+
candidate.class.respond_to?(:table_name)
|
|
83
|
+
end
|
|
68
84
|
end
|
|
69
85
|
private_class_method :version_record?
|
|
70
86
|
|
|
71
87
|
# The same row of the same version table. A record or instant is never a
|
|
72
88
|
# version.
|
|
73
89
|
#: (untyped, untyped) -> bool
|
|
74
|
-
def same_version?(left, right)
|
|
90
|
+
def self.same_version?(left, right)
|
|
75
91
|
version_record?(left) && version_record?(right) &&
|
|
76
92
|
left.class.table_name == right.class.table_name && left.id.to_s == right.id.to_s
|
|
77
93
|
end
|
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
module PaperTrailDiff
|
|
5
5
|
# Query pieces shared by version lookups.
|
|
6
6
|
module VersionQuery
|
|
7
|
-
module_function
|
|
8
|
-
|
|
9
7
|
# Oldest first. Ids break ties between versions written in the same
|
|
10
8
|
# instant, and the timestamp comes first because ids need not follow time:
|
|
11
9
|
# a UUID key does not.
|
|
12
10
|
#: (untyped) -> untyped
|
|
13
|
-
def chronological(relation)
|
|
11
|
+
def self.chronological(relation)
|
|
14
12
|
relation.reorder(created_at: :asc, id: :asc)
|
|
15
13
|
end
|
|
16
14
|
|
|
@@ -19,13 +17,13 @@ module PaperTrailDiff
|
|
|
19
17
|
# leave some out: a history replayed without them credits their changes to
|
|
20
18
|
# the next version kept.
|
|
21
19
|
#: (untyped) -> untyped
|
|
22
|
-
def for_model(model_class)
|
|
20
|
+
def self.for_model(model_class)
|
|
23
21
|
model_class.paper_trail.version_class.where(item_type: model_class.base_class.name)
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
# The versions of the given items, read the same way.
|
|
27
25
|
#: (untyped, untyped) -> untyped
|
|
28
|
-
def for_items(model_class, ids)
|
|
26
|
+
def self.for_items(model_class, ids)
|
|
29
27
|
for_model(model_class).where(item_id: ids)
|
|
30
28
|
end
|
|
31
29
|
|
|
@@ -33,33 +31,35 @@ module PaperTrailDiff
|
|
|
33
31
|
# no other version of the same item that the block accepts is earlier. A
|
|
34
32
|
# correlated NOT EXISTS stays portable where window functions are not.
|
|
35
33
|
#: (untyped) ?{ (untyped) -> untyped } -> untyped
|
|
36
|
-
def no_earlier_version(table, &block)
|
|
37
|
-
|
|
34
|
+
def self.no_earlier_version(table, &block)
|
|
35
|
+
exists(table) { |other| earlier_version(table, other, &block) }.not
|
|
38
36
|
end
|
|
39
37
|
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#: (untyped
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
other
|
|
46
|
-
arel.const_get(:SelectManager).new
|
|
47
|
-
.from(other)
|
|
48
|
-
.project(arel.sql('1'))
|
|
49
|
-
.where(nearer_version(table, other, later: later, &block))
|
|
50
|
-
.exists
|
|
51
|
-
.not
|
|
38
|
+
# Whether a version exists that the block's condition accepts. The block
|
|
39
|
+
# is given the version table under a second name, beside `table`.
|
|
40
|
+
#: (untyped) { (untyped) -> untyped } -> untyped
|
|
41
|
+
def self.exists(table)
|
|
42
|
+
other = other_versions(table)
|
|
43
|
+
Support.arel::SelectManager.new.from(other).project('1').where(yield(other)).exists
|
|
52
44
|
end
|
|
53
45
|
|
|
54
|
-
#: (untyped, untyped
|
|
55
|
-
def
|
|
56
|
-
created_at = other[:created_at]
|
|
57
|
-
nearer = later ? created_at.lt(table[:created_at]) : created_at.gt(table[:created_at])
|
|
46
|
+
#: (untyped, untyped) ?{ (untyped) -> untyped } -> untyped
|
|
47
|
+
def self.earlier_version(table, other)
|
|
58
48
|
same_item = other[:item_type].eq(table[:item_type])
|
|
59
49
|
.and(other[:item_id].eq(table[:item_id]))
|
|
60
|
-
.and(
|
|
50
|
+
.and(other[:created_at].lt(table[:created_at]))
|
|
61
51
|
block_given? ? same_item.and(yield(other)) : same_item
|
|
62
52
|
end
|
|
63
|
-
private_class_method :
|
|
53
|
+
private_class_method :earlier_version
|
|
54
|
+
|
|
55
|
+
# The version table under a second name, for a subquery over it. Any name
|
|
56
|
+
# serves, and SQLite even accepts an empty one other databases refuse, so
|
|
57
|
+
# no spec can tell the mutations apart.
|
|
58
|
+
# mutant:disable
|
|
59
|
+
#: (untyped) -> untyped
|
|
60
|
+
def self.other_versions(table)
|
|
61
|
+
table.alias('paper_trail_diff_other_versions')
|
|
62
|
+
end
|
|
63
|
+
private_class_method :other_versions
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -13,12 +13,12 @@ module PaperTrailDiff
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# Keep both reconstruction boundaries and the step pairs a filter implies.
|
|
16
|
-
#: () -> RootVersionPlan
|
|
17
|
-
def select_plan_for_range
|
|
16
|
+
#: (?whole: bool) -> RootVersionPlan
|
|
17
|
+
def select_plan_for_range(whole: false)
|
|
18
18
|
relation = validated_relation
|
|
19
19
|
select_plan(
|
|
20
20
|
relation.where(created_at: @from.created_at..@to.created_at),
|
|
21
|
-
through: @to
|
|
21
|
+
through: @to, whole: whole
|
|
22
22
|
)
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -34,12 +34,13 @@ module PaperTrailDiff
|
|
|
34
34
|
relation
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
#: (untyped) -> RootVersionPlan
|
|
38
|
-
def select_plan_through_current(current)
|
|
37
|
+
#: (untyped, ?whole: bool) -> RootVersionPlan
|
|
38
|
+
def select_plan_through_current(current, whole: false)
|
|
39
39
|
Endpoint.validate_pair!(@record, current)
|
|
40
40
|
relation = Endpoint.versions(@record)
|
|
41
41
|
validate_boundary!(@from, relation, boundary: :from)
|
|
42
|
-
select_plan(relation.where(created_at: @from.created_at..), live_endpoint: current
|
|
42
|
+
select_plan(relation.where(created_at: @from.created_at..), live_endpoint: current,
|
|
43
|
+
whole: whole)
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
private
|
|
@@ -49,26 +50,21 @@ module PaperTrailDiff
|
|
|
49
50
|
# @rbs @to: untyped
|
|
50
51
|
# @rbs @version_scope: untyped
|
|
51
52
|
|
|
52
|
-
#: (untyped, ?through: untyped, ?live_endpoint: untyped) -> RootVersionPlan
|
|
53
|
-
def select_plan(relation, through: nil, live_endpoint: nil)
|
|
54
|
-
in_range =
|
|
53
|
+
#: (untyped, whole: bool, ?through: untyped, ?live_endpoint: untyped) -> RootVersionPlan
|
|
54
|
+
def select_plan(relation, whole:, through: nil, live_endpoint: nil)
|
|
55
|
+
in_range = relation.select do |version|
|
|
55
56
|
Support.compare_versions(@from, version) <= 0 &&
|
|
56
57
|
(!through || Support.compare_versions(version, through) <= 0)
|
|
57
|
-
end
|
|
58
|
+
end
|
|
58
59
|
RootVersionSelection.new(
|
|
59
60
|
in_range: in_range,
|
|
60
61
|
selected: VersionScopeFilter.new(@version_scope).call(relation, in_range),
|
|
61
62
|
after_range: nil,
|
|
62
63
|
windowed: false,
|
|
63
|
-
|
|
64
|
+
live_endpoint: live_endpoint, whole: whole
|
|
64
65
|
).call
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
#: (Array[untyped]) -> Array[untyped]
|
|
68
|
-
def ordered(versions)
|
|
69
|
-
Support.chronological_sort(versions)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
68
|
#: (untyped, untyped, boundary: Symbol) -> void
|
|
73
69
|
def validate_boundary!(requested, relation, boundary:)
|
|
74
70
|
return if valid_boundary?(requested, relation)
|
|
@@ -21,6 +21,7 @@ module PaperTrailDiff
|
|
|
21
21
|
versions = @from_version.class.transaction(requires_new: true) { ordered_range_versions }
|
|
22
22
|
issues = [] #: Array[DiagnosticIssue?]
|
|
23
23
|
issues << unorderable(versions)
|
|
24
|
+
issues << inverted(versions)
|
|
24
25
|
issues << tied_timestamps(versions) if @fallback_selected
|
|
25
26
|
issues.compact
|
|
26
27
|
rescue StandardError
|
|
@@ -49,6 +50,37 @@ module PaperTrailDiff
|
|
|
49
50
|
)
|
|
50
51
|
end
|
|
51
52
|
|
|
53
|
+
# Versions are read in time order, and ids that count up in one table say
|
|
54
|
+
# which was saved first. A later version dated earlier was usually dated
|
|
55
|
+
# by PaperTrail at an `updated_at` the application set itself, and the
|
|
56
|
+
# history then reads it before the change it followed: an update dated
|
|
57
|
+
# before the record's create reads as the record deleted and created
|
|
58
|
+
# again. A time can also be right and the id wrong, as for versions
|
|
59
|
+
# imported from elsewhere, so this warns rather than refuses.
|
|
60
|
+
#: (Array[untyped]) -> DiagnosticIssue?
|
|
61
|
+
def inverted(versions)
|
|
62
|
+
pair = versions.each_cons(2).find do |left, right|
|
|
63
|
+
Support.orderable_tie?(left, right) && Integer(right.id) < Integer(left.id)
|
|
64
|
+
end
|
|
65
|
+
return unless pair
|
|
66
|
+
|
|
67
|
+
saved_last, saved_first = pair
|
|
68
|
+
DiagnosticIssue.new(
|
|
69
|
+
severity: :warning, code: :inverted_version_order,
|
|
70
|
+
message: inverted_message(saved_first, saved_last), version_id: saved_last.id
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#: (untyped, untyped) -> String
|
|
75
|
+
def inverted_message(saved_first, saved_last)
|
|
76
|
+
"versions #{saved_first.id.inspect} and #{saved_last.id.inspect} were saved in that " \
|
|
77
|
+
'order but are dated the other way round, at ' \
|
|
78
|
+
"#{saved_first.created_at.inspect} and #{saved_last.created_at.inspect}, and history " \
|
|
79
|
+
'reads them in time order; if a save set updated_at itself, which PaperTrail then ' \
|
|
80
|
+
'dates its version at, set has_paper_trail synchronize_version_creation_timestamp: ' \
|
|
81
|
+
'false and correct the stored created_at'
|
|
82
|
+
end
|
|
83
|
+
|
|
52
84
|
# Loaded history orders versions that share a timestamp by id, but PT-AT
|
|
53
85
|
# places association changes by timestamp alone, so a path it reads loses
|
|
54
86
|
# any change between such a pair. Unlike an unorderable sequence this is
|
|
@@ -25,20 +25,24 @@ module PaperTrailDiff
|
|
|
25
25
|
# and an unversioned target has no history to compare.
|
|
26
26
|
#: (untyped) -> untyped
|
|
27
27
|
def self.separate_part(reflection)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
separate_part(part)
|
|
31
|
-
end.first
|
|
28
|
+
[reflection, *AssociationTraversal.through_parts(reflection)].find do |part|
|
|
29
|
+
!part.through_reflection? && separate?(part)
|
|
32
30
|
end
|
|
33
|
-
|
|
31
|
+
end
|
|
32
|
+
private_class_method :separate_part
|
|
33
|
+
|
|
34
|
+
#: (untyped) -> bool
|
|
35
|
+
def self.separate?(reflection)
|
|
36
|
+
return false if reflection.polymorphic?
|
|
34
37
|
|
|
35
38
|
owner = reflection.active_record
|
|
36
39
|
target = reflection.klass
|
|
37
|
-
return unless Support.versioned?(owner) && Support.versioned?(target)
|
|
40
|
+
return false unless Support.versioned?(owner) && Support.versioned?(target)
|
|
41
|
+
return false if tables(owner) == tables(target)
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
true
|
|
40
44
|
end
|
|
41
|
-
private_class_method :
|
|
45
|
+
private_class_method :separate?
|
|
42
46
|
|
|
43
47
|
# PT-AT's version association rows joined to the versions they were saved
|
|
44
48
|
# with. Its `belongs_to :version` names PaperTrail's default class whatever
|
data/lib/paper_trail_diff.rb
CHANGED
|
@@ -7,6 +7,9 @@ require_relative 'paper_trail_diff/version'
|
|
|
7
7
|
require_relative 'paper_trail_diff/support'
|
|
8
8
|
require_relative 'paper_trail_diff/version_query'
|
|
9
9
|
require_relative 'paper_trail_diff/stored_time_precision'
|
|
10
|
+
require_relative 'paper_trail_diff/stored_json_values'
|
|
11
|
+
require_relative 'paper_trail_diff/time_of_day'
|
|
12
|
+
require_relative 'paper_trail_diff/stored_values'
|
|
10
13
|
require_relative 'paper_trail_diff/version_boundary'
|
|
11
14
|
require_relative 'paper_trail_diff/instrumentation'
|
|
12
15
|
require_relative 'paper_trail_diff/deprecation'
|
|
@@ -53,7 +56,6 @@ require_relative 'paper_trail_diff/prepared_association_reifier'
|
|
|
53
56
|
require_relative 'paper_trail_diff/live_association_reader'
|
|
54
57
|
require_relative 'paper_trail_diff/batch_preload'
|
|
55
58
|
require_relative 'paper_trail_diff/live_endpoint_batch_loader'
|
|
56
|
-
require_relative 'paper_trail_diff/preloaded_endpoint_batch_loader'
|
|
57
59
|
require_relative 'paper_trail_diff/live_endpoint_provider'
|
|
58
60
|
require_relative 'paper_trail_diff/live_graph_collector'
|
|
59
61
|
require_relative 'paper_trail_diff/batch_boundary_resolver'
|
|
@@ -61,12 +63,14 @@ require_relative 'paper_trail_diff/comparison_batch'
|
|
|
61
63
|
require_relative 'paper_trail_diff/root_version_plan'
|
|
62
64
|
require_relative 'paper_trail_diff/version_scope_filter'
|
|
63
65
|
require_relative 'paper_trail_diff/root_version_selection'
|
|
66
|
+
require_relative 'paper_trail_diff/own_window'
|
|
64
67
|
require_relative 'paper_trail_diff/batched_root_versions'
|
|
65
68
|
require_relative 'paper_trail_diff/snapshot_normalizer'
|
|
66
69
|
require_relative 'paper_trail_diff/historical_snapshot_store'
|
|
67
70
|
require_relative 'paper_trail_diff/timeline_snapshot_provider'
|
|
68
71
|
require_relative 'paper_trail_diff/activity_event_record_resolver'
|
|
69
72
|
require_relative 'paper_trail_diff/recorded_changes'
|
|
73
|
+
require_relative 'paper_trail_diff/recorded_changes_reader'
|
|
70
74
|
require_relative 'paper_trail_diff/activity_event_route_finder'
|
|
71
75
|
require_relative 'paper_trail_diff/activity_relationship'
|
|
72
76
|
require_relative 'paper_trail_diff/activity_collection_route_change'
|
|
@@ -79,17 +83,23 @@ require_relative 'paper_trail_diff/activity_event_snapshot_refresher'
|
|
|
79
83
|
require_relative 'paper_trail_diff/activity_root_snapshot_refresher'
|
|
80
84
|
require_relative 'paper_trail_diff/branch_snapshot_refresher'
|
|
81
85
|
require_relative 'paper_trail_diff/activity_boundary'
|
|
86
|
+
require_relative 'paper_trail_diff/recorded_columns'
|
|
87
|
+
require_relative 'paper_trail_diff/change_attribution'
|
|
88
|
+
require_relative 'paper_trail_diff/activity_scope_filter'
|
|
82
89
|
require_relative 'paper_trail_diff/activity_view'
|
|
83
90
|
require_relative 'paper_trail_diff/activity_transaction_grouper'
|
|
91
|
+
require_relative 'paper_trail_diff/net_change'
|
|
84
92
|
require_relative 'paper_trail_diff/step'
|
|
85
93
|
require_relative 'paper_trail_diff/analysis'
|
|
86
94
|
require_relative 'paper_trail_diff/activity_root_steps'
|
|
95
|
+
require_relative 'paper_trail_diff/batched_root_analyses'
|
|
87
96
|
require_relative 'paper_trail_diff/analysis_batch'
|
|
88
97
|
require_relative 'paper_trail_diff/deleted_analysis_batch'
|
|
89
98
|
require_relative 'paper_trail_diff/scoped_analysis'
|
|
90
99
|
require_relative 'paper_trail_diff/historical_filter'
|
|
91
100
|
require_relative 'paper_trail_diff/association_activity_edge'
|
|
92
101
|
require_relative 'paper_trail_diff/association_activity_selection'
|
|
102
|
+
require_relative 'paper_trail_diff/total_order'
|
|
93
103
|
require_relative 'paper_trail_diff/scoped_root_selection'
|
|
94
104
|
require_relative 'paper_trail_diff/deleted_root_filter'
|
|
95
105
|
require_relative 'paper_trail_diff/scoped_analysis_builder'
|
|
@@ -104,6 +114,7 @@ require_relative 'paper_trail_diff/timeline_builder'
|
|
|
104
114
|
require_relative 'paper_trail_diff/activity_range'
|
|
105
115
|
require_relative 'paper_trail_diff/activity_event'
|
|
106
116
|
require_relative 'paper_trail_diff/activity_child_candidate_loader'
|
|
117
|
+
require_relative 'paper_trail_diff/prepared_child_candidates'
|
|
107
118
|
require_relative 'paper_trail_diff/activity_target_candidate_loader'
|
|
108
119
|
require_relative 'paper_trail_diff/activity_version_collector'
|
|
109
120
|
require_relative 'paper_trail_diff/activity_snapshot_sequence'
|
|
@@ -151,45 +162,35 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
151
162
|
|
|
152
163
|
class << self # rubocop:disable Metrics/ClassLength
|
|
153
164
|
# Compares net state between explicit PaperTrail-version or current-record endpoints.
|
|
154
|
-
#: (untyped, untyped, ?associations: association_option, ?ignore: ignore_option, ?
|
|
155
|
-
def compare(
|
|
165
|
+
#: (untyped, untyped, ?associations: association_option, ?ignore: ignore_option, ?allow_approximate: bool) -> Diff
|
|
166
|
+
def compare(
|
|
156
167
|
from_version,
|
|
157
168
|
to_version,
|
|
158
169
|
associations: [],
|
|
159
170
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
160
|
-
reload_live_endpoints: nil,
|
|
161
171
|
allow_approximate: false
|
|
162
172
|
)
|
|
163
173
|
PaperTrailAdapter.new(
|
|
164
|
-
associations: associations,
|
|
165
|
-
ignore: ignore,
|
|
166
|
-
reload_live_endpoints: Deprecation.reload_live_endpoints!(reload_live_endpoints),
|
|
167
|
-
allow_approximate: allow_approximate
|
|
174
|
+
associations: associations, ignore: ignore, allow_approximate: allow_approximate
|
|
168
175
|
).compare(from_version, to_version)
|
|
169
176
|
end
|
|
170
177
|
|
|
171
178
|
# Compares many independent endpoint pairs while batching current-record loading.
|
|
172
|
-
#: (Array[comparison_input], ?associations: association_option, ?ignore: ignore_option, ?
|
|
173
|
-
def compare_many(
|
|
179
|
+
#: (Array[comparison_input], ?associations: association_option, ?ignore: ignore_option, ?allow_approximate: bool) -> comparison_results
|
|
180
|
+
def compare_many(
|
|
174
181
|
comparisons,
|
|
175
182
|
associations: [],
|
|
176
183
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
177
|
-
reload_live_endpoints: nil,
|
|
178
|
-
allow_expensive: nil,
|
|
179
184
|
allow_approximate: false
|
|
180
185
|
)
|
|
181
|
-
Deprecation.allow_expensive!(allow_expensive)
|
|
182
186
|
PaperTrailAdapter.new(
|
|
183
|
-
associations: associations,
|
|
184
|
-
ignore: ignore,
|
|
185
|
-
reload_live_endpoints: Deprecation.reload_live_endpoints!(reload_live_endpoints),
|
|
186
|
-
allow_approximate: allow_approximate
|
|
187
|
+
associations: associations, ignore: ignore, allow_approximate: allow_approximate
|
|
187
188
|
).compare_many(comparisons)
|
|
188
189
|
end
|
|
189
190
|
|
|
190
191
|
# Compares every adjacent reconstructed state in an inclusive version range,
|
|
191
192
|
# by default the record's whole history through its current state.
|
|
192
|
-
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?version_scope: untyped, ?
|
|
193
|
+
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?version_scope: untyped, ?allow_approximate: bool) -> Array[Step]
|
|
193
194
|
def timeline( # rubocop:disable Metrics/ParameterLists
|
|
194
195
|
record,
|
|
195
196
|
from: nil,
|
|
@@ -198,10 +199,8 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
198
199
|
associations: [],
|
|
199
200
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
200
201
|
version_scope: nil,
|
|
201
|
-
close_on: nil,
|
|
202
202
|
allow_approximate: false
|
|
203
203
|
)
|
|
204
|
-
Deprecation.close_on!(close_on, within)
|
|
205
204
|
PaperTrailAdapter.new(
|
|
206
205
|
associations: associations, ignore: ignore, allow_approximate: allow_approximate
|
|
207
206
|
).timeline(
|
|
@@ -214,7 +213,7 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
214
213
|
end
|
|
215
214
|
|
|
216
215
|
# Compares adjacent root and selected-descendant activity boundaries.
|
|
217
|
-
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?
|
|
216
|
+
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?recorded_changes: bool, ?allow_approximate: bool) -> Array[ActivityStep]
|
|
218
217
|
def activity_timeline( # rubocop:disable Metrics/ParameterLists
|
|
219
218
|
record,
|
|
220
219
|
from: nil,
|
|
@@ -222,18 +221,14 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
222
221
|
within: nil,
|
|
223
222
|
associations: [],
|
|
224
223
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
225
|
-
reload_live_endpoints: nil,
|
|
226
224
|
version_scope: nil,
|
|
227
|
-
close_on: nil,
|
|
228
225
|
snapshots: false,
|
|
229
226
|
group: nil,
|
|
230
227
|
recorded_changes: false,
|
|
231
228
|
allow_approximate: false
|
|
232
229
|
)
|
|
233
|
-
Deprecation.close_on!(close_on, within)
|
|
234
230
|
PaperTrailAdapter.new(
|
|
235
231
|
associations: associations, ignore: ignore,
|
|
236
|
-
reload_live_endpoints: Deprecation.reload_live_endpoints!(reload_live_endpoints),
|
|
237
232
|
recorded_changes: recorded_changes, allow_approximate: allow_approximate
|
|
238
233
|
).activity_timeline(
|
|
239
234
|
record,
|
|
@@ -247,7 +242,7 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
247
242
|
end
|
|
248
243
|
|
|
249
244
|
# Builds an endpoint diff and root-checkpoint timeline while normalizing each version once.
|
|
250
|
-
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?
|
|
245
|
+
#: (untyped, ?from: untyped, ?to: untyped, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?recorded_changes: bool, ?allow_approximate: bool) -> Analysis
|
|
251
246
|
def analyze( # rubocop:disable Metrics/ParameterLists
|
|
252
247
|
record,
|
|
253
248
|
from: nil,
|
|
@@ -257,13 +252,11 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
257
252
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
258
253
|
activity: false,
|
|
259
254
|
version_scope: nil,
|
|
260
|
-
close_on: nil,
|
|
261
255
|
snapshots: false,
|
|
262
256
|
group: nil,
|
|
263
257
|
recorded_changes: false,
|
|
264
258
|
allow_approximate: false
|
|
265
259
|
)
|
|
266
|
-
Deprecation.close_on!(close_on, within)
|
|
267
260
|
PaperTrailAdapter.new(
|
|
268
261
|
associations: associations, ignore: ignore, recorded_changes: recorded_changes,
|
|
269
262
|
allow_approximate: allow_approximate
|
|
@@ -284,7 +277,7 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
284
277
|
# returns a frozen Hash keyed by identity. Roots with nothing to report in
|
|
285
278
|
# the window return an empty `Analysis`. To let a relation choose the
|
|
286
279
|
# records, use `analyze_scope`.
|
|
287
|
-
#: (Array[untyped], ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?
|
|
280
|
+
#: (Array[untyped], ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?recorded_changes: bool, ?allow_approximate: bool) -> Hash[identity, Analysis]
|
|
288
281
|
def analyze_many( # rubocop:disable Metrics/ParameterLists
|
|
289
282
|
records,
|
|
290
283
|
within: nil,
|
|
@@ -292,15 +285,11 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
292
285
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
293
286
|
activity: false,
|
|
294
287
|
version_scope: nil,
|
|
295
|
-
close_on: nil,
|
|
296
288
|
snapshots: false,
|
|
297
289
|
group: nil,
|
|
298
|
-
allow_expensive: nil,
|
|
299
290
|
recorded_changes: false,
|
|
300
291
|
allow_approximate: false
|
|
301
292
|
)
|
|
302
|
-
Deprecation.close_on!(close_on, within)
|
|
303
|
-
Deprecation.allow_expensive!(allow_expensive)
|
|
304
293
|
PaperTrailAdapter.new(
|
|
305
294
|
associations: associations, ignore: ignore,
|
|
306
295
|
recorded_changes: recorded_changes, allow_approximate: allow_approximate
|
|
@@ -334,7 +323,7 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
334
323
|
# Note also that a relation selects on current state, not on state during
|
|
335
324
|
# the window: `where(status: 'published')` means published *now*, which is a
|
|
336
325
|
# different set from what was published while the window was open.
|
|
337
|
-
#: (untyped, limit: Integer?, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?
|
|
326
|
+
#: (untyped, limit: Integer?, ?within: untyped, ?associations: association_option, ?ignore: ignore_option, ?activity: bool, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?historical_filter: untyped, ?max_filter_versions: Integer, ?include_deleted: bool, ?recorded_changes: bool, ?allow_approximate: bool) -> ScopedAnalysis
|
|
338
327
|
def analyze_scope( # rubocop:disable Metrics/ParameterLists
|
|
339
328
|
scope,
|
|
340
329
|
limit:,
|
|
@@ -343,18 +332,14 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
343
332
|
ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
344
333
|
activity: false,
|
|
345
334
|
version_scope: nil,
|
|
346
|
-
close_on: nil,
|
|
347
335
|
snapshots: false,
|
|
348
336
|
group: nil,
|
|
349
337
|
historical_filter: nil,
|
|
350
338
|
max_filter_versions: HistoricalFilter::DEFAULT_VERSION_LIMIT,
|
|
351
339
|
include_deleted: false,
|
|
352
|
-
allow_expensive: nil,
|
|
353
340
|
recorded_changes: false,
|
|
354
341
|
allow_approximate: false
|
|
355
342
|
)
|
|
356
|
-
Deprecation.close_on!(close_on, within)
|
|
357
|
-
Deprecation.allow_expensive!(allow_expensive)
|
|
358
343
|
adapter = PaperTrailAdapter.new(associations: associations, ignore: ignore,
|
|
359
344
|
recorded_changes: recorded_changes,
|
|
360
345
|
allow_approximate: allow_approximate)
|
|
@@ -370,12 +355,12 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
370
355
|
# for every root that changed or whose requested associations did.
|
|
371
356
|
# Historical windows remain explicit on analyze_scope; this entry point is
|
|
372
357
|
# deliberately named for a report through now rather than an as-of query.
|
|
373
|
-
#: (untyped, since: untyped, limit: Integer, ?associations: association_option, ?ignore: ignore_option, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?include_deleted: bool, ?historical_filter: untyped, ?max_filter_versions: Integer, ?
|
|
358
|
+
#: (untyped, since: untyped, limit: Integer, ?associations: association_option, ?ignore: ignore_option, ?version_scope: untyped, ?snapshots: bool, ?group: Symbol?, ?include_deleted: bool, ?historical_filter: untyped, ?max_filter_versions: Integer, ?recorded_changes: bool, ?allow_approximate: bool) -> ScopedAnalysis
|
|
374
359
|
def report( # rubocop:disable Metrics/ParameterLists
|
|
375
360
|
scope, since:, limit:, associations: [], ignore: DEFAULT_IGNORED_ATTRIBUTES,
|
|
376
361
|
version_scope: nil, snapshots: false, group: nil, include_deleted: false,
|
|
377
362
|
historical_filter: nil, max_filter_versions: HistoricalFilter::DEFAULT_VERSION_LIMIT,
|
|
378
|
-
|
|
363
|
+
recorded_changes: false, allow_approximate: false
|
|
379
364
|
)
|
|
380
365
|
# A range here would become the start of another range.
|
|
381
366
|
if since.nil? || since.is_a?(Range)
|
|
@@ -383,13 +368,14 @@ module PaperTrailDiff # rubocop:disable Metrics/ModuleLength
|
|
|
383
368
|
'pass it as `within:` to analyze_scope'
|
|
384
369
|
end
|
|
385
370
|
|
|
371
|
+
# Endless, so a version a server dated ahead of this one's clock is in it.
|
|
386
372
|
analyze_scope(
|
|
387
373
|
scope,
|
|
388
|
-
within: since..
|
|
374
|
+
within: (since..), limit: limit, associations: associations,
|
|
389
375
|
ignore: ignore, activity: true, version_scope: version_scope, snapshots: snapshots,
|
|
390
376
|
group: group,
|
|
391
377
|
include_deleted: include_deleted, historical_filter: historical_filter,
|
|
392
|
-
max_filter_versions: max_filter_versions,
|
|
378
|
+
max_filter_versions: max_filter_versions,
|
|
393
379
|
recorded_changes: recorded_changes, allow_approximate: allow_approximate
|
|
394
380
|
)
|
|
395
381
|
end
|
|
@@ -17,11 +17,6 @@ module PaperTrailDiff
|
|
|
17
17
|
|
|
18
18
|
@route_finder: ActivityEventRouteFinder
|
|
19
19
|
|
|
20
|
-
# An edit can move a target into or out of a scope, which a replacement
|
|
21
|
-
# in place cannot show, so a scoped route's branch is read again instead.
|
|
22
|
-
# : (Array[Array[untyped]]) -> bool
|
|
23
|
-
def scoped_route?: (Array[Array[untyped]]) -> bool
|
|
24
|
-
|
|
25
20
|
# : (Array[untyped], untyped, SnapshotNormalizer, untyped, untyped) -> RecordSnapshot?
|
|
26
21
|
def normalized_route_record: (Array[untyped], untyped, SnapshotNormalizer, untyped, untyped) -> RecordSnapshot?
|
|
27
22
|
|
|
@@ -39,8 +34,5 @@ module PaperTrailDiff
|
|
|
39
34
|
# row whose type changes is replaced by a record of another class.
|
|
40
35
|
# : (RecordSnapshot, untyped) -> bool
|
|
41
36
|
def same_table?: (RecordSnapshot, untyped) -> bool
|
|
42
|
-
|
|
43
|
-
# : (untyped) -> untyped
|
|
44
|
-
def endpoint_model_class: (untyped) -> untyped
|
|
45
37
|
end
|
|
46
38
|
end
|