active_snapshot 0.5.1 → 0.5.2

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: d5fd89751eb3c64739f2a3242edfb4a8f3fd1dfce8047bbd4db51b790039ee39
4
- data.tar.gz: 5cf804fd3bb81be067153fa1120b45f5045febf0eb93921950ae51bea17c65a8
3
+ metadata.gz: 170e9249f3a190a13d266d247f3d11c96ce3f1a0eedb4660aaf17a16fccb9a55
4
+ data.tar.gz: c8a233b6eccb33f331fefa0020225f57d99cb2ffe4ec528e3dd0bb7509383816
5
5
  SHA512:
6
- metadata.gz: c079cdc615a35293cecbe0ab3c86df6a0b96e6bc0a1a92beb5b8580735d4a61209aa97623a18d9e06aeffeb109f94bbc742cea119e96421ba725ed9a22aae1eb
7
- data.tar.gz: dad4d76b90fd8caa0dbd09a2c20d618bd6b8060de77eacbbad4eeda7d79cfa13be48fed5888f80122c607f8ce69acdf67eb7ce48707f54bd08dc3e8f9922604b
6
+ metadata.gz: 25dd13a665ef38d7a5fbc9f461e531195753742b2968007616e3ebc5427d31c8e68188153091708f488137bc8de7ac09dbca2cd23c79af03fd6f2c607c5df7c7
7
+ data.tar.gz: b8277f58992d150915f477160f6e95f4863bea51563403b8c6e8c6d13237796747fb41491509d490be79d51bd0f6c33313c83e93048a6c34da0c1acfa915cea4
data/CHANGELOG.md CHANGED
@@ -2,9 +2,14 @@ CHANGELOG
2
2
  ---------
3
3
 
4
4
  - **Unreleased**
5
- * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.1...master)
5
+ * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.2...master)
6
6
  * Nothing yet
7
7
 
8
+ - **Unreleased**
9
+ * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.1...v0.5.2)
10
+ * [#67](https://github.com/westonganger/active_snapshot/pull/67) - Switch default storage method to native SQL JSON columns. No longer recommend to set `ActiveSnapshot.config.storage_method`, its only retained to support legacy installations
11
+ * Drop support for Rails 6.0. Rails 6.1 is minimum required version now.
12
+
8
13
  - **v0.5.1** - Nov 11, 2024
9
14
  * [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.0...v0.5.1)
10
15
  * [#66](https://github.com/westonganger/active_snapshot/pull/66) - Ensure `SnapshotItem#restore_item!` and `Snapshot#fetch_reified_items` bypass assignment for snapshot object data where the associated column no longer exists.
data/README.md CHANGED
@@ -53,25 +53,6 @@ It defines an optional extension to your model: `has_snapshot_children`.
53
53
 
54
54
  It defines one instance method to your model: `create_snapshot!`
55
55
 
56
- # Using a different storage format
57
-
58
- By default ActiveSnapshot encodes objects to JSON and stores in the database as plain text. If you prefer to have YAML encoded columns or native JSON DB columns you can configure this as follows:
59
-
60
- ```ruby
61
- ActiveSnapshot.config do |config|
62
- config.storage_method = "serialized_json" # default, for text column
63
- #config.storage_method = "serialized_yaml" # for text column
64
- #config.storage_method = "native_json" # for json/jsonb column
65
- end
66
- ```
67
-
68
- If using a native json column, you should configure the `storage_method` before generating the migration. If this step was missed then you would need to create a migration to change the `:object` and `:metadata` columns to json (or jsonb)
69
-
70
- ```ruby
71
- change_column :snapshots, :object, :json
72
- change_column :snapshots, :metadata, :json
73
- ```
74
-
75
56
  # Basic Usage
76
57
 
77
58
  You now have access to the following methods:
@@ -1,12 +1,24 @@
1
1
  module ActiveSnapshot
2
2
  class Config
3
- attr_reader :storage_method
4
-
5
3
  def initialize
6
- @storage_method = 'serialized_json'
4
+ end
5
+
6
+ def storage_method
7
+ if @storage_method.nil?
8
+ if ActiveSnapshot::SnapshotItem.table_exists? && ActiveSnapshot::SnapshotItem.type_for_attribute(:object).type == :text
9
+ # for legacy active_snapshot configurations only
10
+ self.storage_method = 'serialized_json'
11
+ else
12
+ self.storage_method = 'native_json'
13
+ end
14
+ end
15
+
16
+ @storage_method
7
17
  end
8
18
 
9
19
  def storage_method=(value)
20
+ # for legacy active_snapshot configurations only
21
+
10
22
  value_str = value.to_s
11
23
 
12
24
  if ['serialized_yaml', 'serialized_json', 'native_json'].include?(value_str)
@@ -17,15 +29,15 @@ module ActiveSnapshot
17
29
  end
18
30
 
19
31
  def storage_method_yaml?
20
- @storage_method == 'serialized_yaml'
32
+ # for legacy active_snapshot configurations only
33
+ storage_method == 'serialized_yaml'
21
34
  end
22
35
 
23
- def storage_method_json?
24
- @storage_method == 'serialized_json'
36
+ def storage_method_serialized_json?
37
+ # for legacy active_snapshot configurations only
38
+ storage_method == 'serialized_json'
25
39
  end
40
+ alias_method :storage_method_json?, :storage_method_serialized_json?
26
41
 
27
- def storage_method_native_json?
28
- @storage_method == 'native_json'
29
- end
30
42
  end
31
43
  end
@@ -18,9 +18,11 @@ module ActiveSnapshot
18
18
  def metadata
19
19
  return @metadata if @metadata
20
20
 
21
- if ActiveSnapshot.config.storage_method_json?
21
+ if ActiveSnapshot.config.storage_method_serialized_json?
22
+ # for legacy active_snapshot configurations only
22
23
  @metadata = JSON.parse(self[:metadata])
23
24
  elsif ActiveSnapshot.config.storage_method_yaml?
25
+ # for legacy active_snapshot configurations only
24
26
  yaml_method = "unsafe_load"
25
27
 
26
28
  if !YAML.respond_to?("unsafe_load")
@@ -28,7 +30,7 @@ module ActiveSnapshot
28
30
  end
29
31
 
30
32
  @metadata = YAML.send(yaml_method, self[:metadata])
31
- elsif ActiveSnapshot.config.storage_method_native_json?
33
+ else
32
34
  @metadata = self[:metadata]
33
35
  end
34
36
  end
@@ -36,11 +38,13 @@ module ActiveSnapshot
36
38
  def metadata=(h)
37
39
  @metadata = nil
38
40
 
39
- if ActiveSnapshot.config.storage_method_json?
41
+ if ActiveSnapshot.config.storage_method_serialized_json?
42
+ # for legacy active_snapshot configurations only
40
43
  self[:metadata] = h.to_json
41
44
  elsif ActiveSnapshot.config.storage_method_yaml?
45
+ # for legacy active_snapshot configurations only
42
46
  self[:metadata] = YAML.dump(h)
43
- elsif ActiveSnapshot.config.storage_method_native_json?
47
+ else
44
48
  self[:metadata] = h
45
49
  end
46
50
  end
@@ -17,27 +17,29 @@ module ActiveSnapshot
17
17
  def object
18
18
  return @object if @object
19
19
 
20
- if ActiveSnapshot.config.storage_method_json?
20
+ if ActiveSnapshot.config.storage_method_serialized_json?
21
+ # for legacy active_snapshot configurations only
21
22
  @object = self[:object] ? JSON.parse(self[:object]) : {}
22
23
  elsif ActiveSnapshot.config.storage_method_yaml?
24
+ # for legacy active_snapshot configurations only
23
25
  yaml_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
24
26
 
25
27
  @object = self[:object] ? YAML.public_send(yaml_method, self[:object]) : {}
26
- elsif ActiveSnapshot.config.storage_method_native_json?
27
- @object = self[:object]
28
28
  else
29
- raise StandardError, "Unsupported storage_method: `#{ActiveSnapshot.config.storage_method}`"
29
+ @object = self[:object]
30
30
  end
31
31
  end
32
32
 
33
33
  def object=(h)
34
34
  @object = nil
35
35
 
36
- if ActiveSnapshot.config.storage_method_json?
36
+ if ActiveSnapshot.config.storage_method_serialized_json?
37
+ # for legacy active_snapshot configurations only
37
38
  self[:object] = h.to_json
38
39
  elsif ActiveSnapshot.config.storage_method_yaml?
40
+ # for legacy active_snapshot configurations only
39
41
  self[:object] = YAML.dump(h)
40
- elsif ActiveSnapshot.config.storage_method_native_json?
42
+ else
41
43
  self[:object] = h
42
44
  end
43
45
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveSnapshot
2
- VERSION = "0.5.1".freeze
2
+ VERSION = "0.5.2".freeze
3
3
  end
@@ -8,7 +8,7 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
8
8
  t.string :identifier, index: true
9
9
  t.index [:identifier, :item_id, :item_type], unique: true
10
10
 
11
- t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :metadata
11
+ t.json :metadata
12
12
 
13
13
  t.datetime :created_at, null: false
14
14
  end
@@ -18,7 +18,7 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
18
18
  t.belongs_to :item, polymorphic: true, null: false, index: true
19
19
  t.index [:snapshot_id, :item_id, :item_type], unique: true
20
20
 
21
- t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :object, null: false
21
+ t.json :object, null: false
22
22
 
23
23
  t.datetime :created_at, null: false
24
24
  t.string :child_group_name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.1'
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: '6.0'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement