active_snapshot 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffb14fbf0391e0fb8c91c363740372b0e9688711ed41e620fd1707c690562cb5
4
- data.tar.gz: 60c00ff5bd2266bfebc2411945f4f6b8cb9f1435ef9b012a582fffbf2e10b73c
3
+ metadata.gz: 5b48af4ad66af3d9fe9110f544df49f29ec6586969cb7e2c7f62431b54163a84
4
+ data.tar.gz: fddc58303f066d5b77b56304c4367874e2b3dda0ea2e76e710d81a0f1705861e
5
5
  SHA512:
6
- metadata.gz: 729687b8c87777eeb8d2dd923b67917ae9000fe73d604517ecdb2410361d659c437bbe9c491c89927942540edf2fc12cdab8ca51cc7c4e3c9dfd1443e2a2b669
7
- data.tar.gz: 25690387b0d2ec4ee5f951579c038e4cddedbd9f5ba3bf3aaafdfe8eeace856004203ffb940fc5581baf0ee31993168a78502774cb36173e85900bb9428e1ff4
6
+ metadata.gz: 9a769fccb45b11f7163384b6ee79e5ff056b897cb3f382bb48054eaf9e20dba87371ab6b42da4ac117eafd136ebdc5d2dcd3441c7cf3a397ea087ec481dbc61d
7
+ data.tar.gz: 2ca41b8874d1511596e25893ddb9b0b05daeead16a12150ff25b1812b1dd3f2901fdcad501ece2681b4a96161e8909e5fd475d52e8c7eda72d74e83804b38574
data/CHANGELOG.md CHANGED
@@ -2,9 +2,13 @@ CHANGELOG
2
2
  ---------
3
3
 
4
4
  - **Unreleased**
5
- * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.2...master)
5
+ * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.4.0...master)
6
6
  * Nothing yet
7
7
 
8
+ - **v0.4.0** - July 23, 2024
9
+ * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.2...v0.4.0)
10
+ * [#44](https://github.com/westonganger/active_snapshot/pull/44) - Remove dependency on activerecord-import with vanilla ActiveRecord upsert_all
11
+
8
12
  - **v0.3.2** - Oct 17, 2023
9
13
  * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.1...v0.3.2)
10
14
  * [#43](https://github.com/westonganger/active_snapshot/pull/43) - Fix unique index error in generated DB migration
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ActiveSnapshot
2
2
 
3
3
  <a href="https://badge.fury.io/rb/active_snapshot" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/active_snapshot.svg" alt="Gem Version"></a>
4
- <a href='https://github.com/westonganger/active_snapshot/actions' target='_blank'><img src="https://github.com/westonganger/active_snapshot/workflows/Tests/badge.svg" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
4
+ <a href='https://github.com/westonganger/active_snapshot/actions' target='_blank'><img src="https://github.com/westonganger/active_snapshot/actions/workflows/test.yml/badge.svg?branch=master" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
5
5
  <a href='https://rubygems.org/gems/active_snapshot' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://img.shields.io/gem/dt/active_snapshot?color=brightgreen&label=Rubygems%20Downloads' border='0' alt='RubyGems Downloads' /></a>
6
6
 
7
7
  Simplified snapshots and restoration for ActiveRecord models and associations with a transparent white-box implementation.
@@ -101,24 +101,24 @@ snapshot.destroy!
101
101
  ```ruby
102
102
  class Post < ActiveRecord::Base
103
103
  include ActiveSnapshot
104
-
104
+
105
105
  has_snapshot_children do
106
106
  ### Executed in the context of the instance / self
107
107
 
108
108
  ### Reload record from database to ensure a clean state and eager load the specified associations
109
109
  instance = self.class.includes(:tags, :ip_address, comments: [:comment_sub_records]).find(id)
110
-
110
+
111
111
  ### Define the associated records that will be restored
112
112
  {
113
113
  comments: instance.comments,
114
-
114
+
115
115
  ### Nested Associations can be handled by simply mapping them into an array
116
- comment_sub_records: instance.comments.flat_map{|x| x.comment_sub_records },
117
-
116
+ comment_sub_records: instance.comments.flat_map{|x| x.comment_sub_records },
117
+
118
118
  tags: {
119
119
  records: instance.tags
120
120
  },
121
-
121
+
122
122
  ip_address: {
123
123
  record: instance.ip_address,
124
124
  delete_method: ->(item){ item.release! }
@@ -133,7 +133,7 @@ Now when you run `create_snapshot!` the associations will be tracked accordingly
133
133
 
134
134
  # Reifying Snapshot Items
135
135
 
136
- You can view all of the reified snapshot items by calling the following method. Its completely up to you on how to use this data.
136
+ You can view all of the reified snapshot items by calling the following method. Its completely up to you on how to use this data.
137
137
 
138
138
  ```ruby
139
139
  reified_parent, reified_children_hash = snapshot.fetch_reified_items
@@ -22,21 +22,23 @@ module ActiveSnapshot
22
22
  metadata: (metadata || {}),
23
23
  })
24
24
 
25
- snapshot_items = []
25
+ new_entries = []
26
26
 
27
- snapshot_items << snapshot.build_snapshot_item(self)
27
+ current_time = Time.now
28
+
29
+ new_entries << snapshot.build_snapshot_item(self).attributes.merge(created_at: current_time)
28
30
 
29
31
  snapshot_children = self.children_to_snapshot
30
32
 
31
33
  if snapshot_children
32
34
  snapshot_children.each do |child_group_name, h|
33
35
  h[:records].each do |child_item|
34
- snapshot_items << snapshot.build_snapshot_item(child_item, child_group_name: child_group_name)
36
+ new_entries << snapshot.build_snapshot_item(child_item, child_group_name: child_group_name).attributes.merge(created_at: current_time)
35
37
  end
36
38
  end
37
39
  end
38
40
 
39
- SnapshotItem.import(snapshot_items, validate: true)
41
+ SnapshotItem.upsert_all(new_entries.map{|x| x.delete("id"); x }, returning: false)
40
42
 
41
43
  snapshot
42
44
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveSnapshot
2
- VERSION = "0.3.2".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -4,8 +4,6 @@ require "active_snapshot/config"
4
4
  require 'active_support/lazy_load_hooks'
5
5
 
6
6
  ActiveSupport.on_load(:active_record) do
7
- require "activerecord-import"
8
-
9
7
  require "active_snapshot/models/snapshot"
10
8
  require "active_snapshot/models/snapshot_item"
11
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-17 00:00:00.000000000 Z
11
+ date: 2024-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: activerecord-import
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -177,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
163
  - !ruby/object:Gem::Version
178
164
  version: '0'
179
165
  requirements: []
180
- rubygems_version: 3.4.6
166
+ rubygems_version: 3.4.22
181
167
  signing_key:
182
168
  specification_version: 4
183
169
  summary: Dead simple snapshot versioning for ActiveRecord models and associations.