active_snapshot 0.2.1 → 0.2.4
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 +15 -1
- data/README.md +2 -2
- data/lib/active_snapshot/models/concerns/snapshots_concern.rb +3 -4
- data/lib/active_snapshot/models/snapshot.rb +8 -2
- data/lib/active_snapshot/models/snapshot_item.rb +7 -1
- data/lib/active_snapshot/version.rb +1 -1
- data/lib/generators/active_snapshot/install/templates/create_snapshots_tables.rb.erb +1 -1
- data/test/dummy_app/app/models/parent_without_children.rb +5 -0
- data/test/dummy_app/app/models/post.rb +1 -0
- data/test/dummy_app/app/models/sub_post.rb +11 -0
- data/test/dummy_app/config/application.rb +0 -8
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +2803 -805
- data/test/models/snapshot_test.rb +31 -0
- data/test/models/snapshots_concern_test.rb +1 -3
- data/test/test_helper.rb +1 -1
- metadata +35 -35
- data/test/dummy_app/config/environments/development.rb +0 -30
- data/test/dummy_app/config/environments/production.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 204744938dec9e53545cc73a6497d47b9463b76b0622491d442b5ed4169b7c83
|
4
|
+
data.tar.gz: dee647e71ff99f91e79764f6094e9253fa74b9641e6f2e611ea10485e3d1d570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9542a0beecba0f52d3d25f0dfbd1197f31eb4ab9758f7ccfaf0e5455dfd150ef6ee1ba81fc138383ff8004a9e26a037a6ad72c004766bac1f0a3bf68edb4e6
|
7
|
+
data.tar.gz: eeab5ae90f2dc09f34ece44aa51992df834cf552693849d4595554e08448d4d8fceac954cb5ccbbe47089b1a868eeb089b5391ed3cf8a410aad6d436e6a3ef6a
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,23 @@ CHANGELOG
|
|
2
2
|
---------
|
3
3
|
|
4
4
|
- **UNRELEASED**
|
5
|
-
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.
|
5
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.4...master)
|
6
6
|
* Nothing yet
|
7
7
|
|
8
|
+
- **v0.2.4** - Feb 25, 2022
|
9
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.3...v0.2.4)
|
10
|
+
* [PR #20](https://github.com/westonganger/active_snapshot/pull/20) - Resolve error when `has_snapshot_children` has not been defined as it should be optional
|
11
|
+
* [PR #18](https://github.com/westonganger/active_snapshot/pull/18) - Fix bug where sub-classes of a model would not be assigned correctly as parent when restoring
|
12
|
+
|
13
|
+
- **v0.2.3** - Jan 7, 2022
|
14
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.2...v0.2.3)
|
15
|
+
* Support Ruby 3.1 using `YAML.unsafe_load`
|
16
|
+
* Fix unique constraint on snapshots.identifier column
|
17
|
+
|
18
|
+
- **v0.2.2** - August 27, 2021
|
19
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.1...v0.2.2)
|
20
|
+
* [0715279](https://github.com/westonganger/active_snapshot/commit/0715279) - Fix bug on restore for in `has_snapshot_children` method with nil association values
|
21
|
+
|
8
22
|
- **v0.2.1** - August 19, 2021
|
9
23
|
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.0...v0.2.1)
|
10
24
|
* [76b6bd9](https://github.com/westonganger/active_snapshot/commit/76b6bd951f73b277891976c458a0cdef0bd77af5) - Improve `has_snapshot_children` method to support single records and nil values which can occur with has_one/belongs_to relationships
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ snapshot.restore!
|
|
77
77
|
snapshot.destroy!
|
78
78
|
```
|
79
79
|
|
80
|
-
#
|
80
|
+
# Tracking Associated / Child Records
|
81
81
|
|
82
82
|
```ruby
|
83
83
|
class Post < ActiveRecord::Base
|
@@ -93,7 +93,7 @@ class Post < ActiveRecord::Base
|
|
93
93
|
{
|
94
94
|
comments: instance.comments,
|
95
95
|
|
96
|
-
###
|
96
|
+
### Nested Associations can be handled by simply mapping them into an array
|
97
97
|
comment_sub_records: instance.comments.flat_map{|x| x.comment_sub_records },
|
98
98
|
|
99
99
|
tags: {
|
@@ -38,9 +38,7 @@ module ActiveSnapshot
|
|
38
38
|
class_methods do
|
39
39
|
|
40
40
|
def has_snapshot_children(&block)
|
41
|
-
if
|
42
|
-
raise ArgumentError.new("Invalid `has_snapshot_children` requires block to be defined")
|
43
|
-
elsif block_given?
|
41
|
+
if block_given?
|
44
42
|
@snapshot_children_proc = block
|
45
43
|
else
|
46
44
|
@snapshot_children_proc
|
@@ -69,7 +67,8 @@ module ActiveSnapshot
|
|
69
67
|
snapshot_children[assoc_name] = {}
|
70
68
|
|
71
69
|
if opts.nil?
|
72
|
-
|
70
|
+
### nil is allowed value in case has_one/belongs_to is nil, etc.
|
71
|
+
snapshot_children[assoc_name][:records] = []
|
73
72
|
|
74
73
|
elsif opts.is_a?(ActiveRecord::Base)
|
75
74
|
### Support belongs_to / has_one
|
@@ -16,7 +16,13 @@ module ActiveSnapshot
|
|
16
16
|
validates :user_type, presence: true, if: :user_id
|
17
17
|
|
18
18
|
def metadata
|
19
|
-
|
19
|
+
yaml_method = "unsafe_load"
|
20
|
+
|
21
|
+
if !YAML.respond_to?("unsafe_load")
|
22
|
+
yaml_method = "load"
|
23
|
+
end
|
24
|
+
|
25
|
+
@metadata ||= YAML.send(yaml_method, self[:metadata]).with_indifferent_access
|
20
26
|
end
|
21
27
|
|
22
28
|
def metadata=(h)
|
@@ -92,7 +98,7 @@ module ActiveSnapshot
|
|
92
98
|
|
93
99
|
reified_children_hash[key] << reified_item
|
94
100
|
|
95
|
-
elsif
|
101
|
+
elsif self.item_id == si.item_id && (self.item_type == si.item_type || si.item_type.constantize.new.is_a?(self.item_type.constantize))
|
96
102
|
reified_parent = reified_item
|
97
103
|
end
|
98
104
|
end
|
@@ -14,7 +14,13 @@ module ActiveSnapshot
|
|
14
14
|
validates :item_type, presence: true, uniqueness: { scope: [:snapshot_id, :item_id] }
|
15
15
|
|
16
16
|
def object
|
17
|
-
|
17
|
+
yaml_method = "unsafe_load"
|
18
|
+
|
19
|
+
if !YAML.respond_to?("unsafe_load")
|
20
|
+
yaml_method = "load"
|
21
|
+
end
|
22
|
+
|
23
|
+
@metadata ||= YAML.send(yaml_method, self[:object]).with_indifferent_access
|
18
24
|
end
|
19
25
|
|
20
26
|
def object=(h)
|
@@ -3,7 +3,7 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
|
|
3
3
|
def change
|
4
4
|
create_table :snapshots<%= table_options %> do |t|
|
5
5
|
t.belongs_to :item, polymorphic: true, null: false, index: true
|
6
|
-
t.string :identifier, null: false, unique:
|
6
|
+
t.string :identifier, null: false, unique: [:item_id, :item_type], index: true
|
7
7
|
t.belongs_to :user, polymorphic: true
|
8
8
|
t.text :metadata
|
9
9
|
t.datetime :created_at, null: false
|
@@ -34,14 +34,6 @@ module Dummy
|
|
34
34
|
# Configure sensitive parameters which will be filtered from the log file.
|
35
35
|
config.filter_parameters += [:password]
|
36
36
|
|
37
|
-
# Enable the asset pipeline
|
38
|
-
config.assets.enabled = true
|
39
|
-
|
40
|
-
config.assets.quiet = true
|
41
|
-
|
42
|
-
# Version of your assets, change this if you want to expire all your assets
|
43
|
-
config.assets.version = '1.0'
|
44
|
-
|
45
37
|
config.generators.test_framework = false
|
46
38
|
config.generators.helper = false
|
47
39
|
config.generators.stylesheets = false
|
Binary file
|