active_snapshot 0.2.1 → 0.2.4

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: 887284049e06d4698fccfb7434fe8e09245ea8a028c03592a0d04905e5ebe74f
4
- data.tar.gz: d62943f9f6e392d3c51c9d19112040df9d2027722074169b87c911e923a0623d
3
+ metadata.gz: 204744938dec9e53545cc73a6497d47b9463b76b0622491d442b5ed4169b7c83
4
+ data.tar.gz: dee647e71ff99f91e79764f6094e9253fa74b9641e6f2e611ea10485e3d1d570
5
5
  SHA512:
6
- metadata.gz: be3291eda618c5989e812da726a27d660a54caf1647d30cb136b1029600a9e049dbeeb5331d7d3035c61c7dc9e99de1e9db63ee151c12a81e9352b241257852d
7
- data.tar.gz: 11e657296fbde5aa2f3ae7b82d35ed48658eeff915bd24e23602ad06aa7eef000fa6feaf601b1f03633dd594a126835a810dc824e777dfd6a954f1fce441f9eb
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.1...master)
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
- # Restoring Associated / Child Records
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
- ### to handle any nested associations simply map them into an array
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 !block_given? && !defined?(@snapshot_children_proc)
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
- next # skip, nil is allowed value in case has_one/belongs_to is nil, etc.
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
- @metadata ||= YAML.load(self[:metadata]).with_indifferent_access
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 [self.item_id, self.item_type] == [si.item_id, si.item_type]
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
- @object ||= YAML.load(self[:object]).with_indifferent_access
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)
@@ -1,3 +1,3 @@
1
1
  module ActiveSnapshot
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
@@ -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: true, index: true
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
@@ -0,0 +1,5 @@
1
+ class ParentWithoutChildren < ApplicationRecord
2
+ include ActiveSnapshot
3
+
4
+ self.table_name = "posts"
5
+ end
@@ -10,6 +10,7 @@ class Post < ActiveRecord::Base
10
10
  {
11
11
  comments: instance.comments,
12
12
  notes: instance.notes,
13
+ nil_assoc: nil,
13
14
  }
14
15
  end
15
16
  end
@@ -0,0 +1,11 @@
1
+ class SubPost < Post
2
+ has_snapshot_children do
3
+ instance = self.class.includes(:comments, :notes).find(id)
4
+
5
+ {
6
+ comments: instance.comments,
7
+ notes: instance.notes,
8
+ nil_assoc: nil,
9
+ }
10
+ end
11
+ end
@@ -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