hoardable 0.1.3 → 0.1.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/README.md +18 -3
- data/lib/hoardable/hoardable.rb +1 -4
- data/lib/hoardable/model.rb +23 -0
- data/lib/hoardable/source_model.rb +12 -4
- data/lib/hoardable/version.rb +1 -1
- data/sig/hoardable.rbs +83 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5e5c29b0b6d4a24e7b41a9b4846fd1288caabd48158b517a4b9b61e53421d1c
|
4
|
+
data.tar.gz: 1e863147db8e3a39e4ed3d465855d465f14c4c8a444426abce72534e8bae4d9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c997b34958fbe6253098778c03bf9226eac02b7fd218af1a1d1bd52527b7b1a0b0406a6ecf0cc8e3ea45d70e5b8823dc23a0e48fcc741c470831b98adb3fd65
|
7
|
+
data.tar.gz: 44b9c1cfe68aa6ab18370b90632d5563dda8ef50b0cde425be3b44eb7f2027fa6e61d609538653cc15adab20f9d79ba3423f614d95c9413f8db4c0ced3a2f4be
|
data/README.md
CHANGED
@@ -222,19 +222,22 @@ end
|
|
222
222
|
|
223
223
|
### Configuration
|
224
224
|
|
225
|
-
There are
|
225
|
+
There are three configurable options currently:
|
226
226
|
|
227
227
|
```ruby
|
228
228
|
Hoardable.enabled # => default true
|
229
|
+
Hoardable.version_updates # => default true
|
229
230
|
Hoardable.save_trash # => default true
|
230
231
|
```
|
231
232
|
|
232
|
-
`Hoardable.enabled` controls whether versions will be
|
233
|
+
`Hoardable.enabled` controls whether versions will be ever be created.
|
234
|
+
|
235
|
+
`Hoardable.version_updates` controls whether versions get created on record updates.
|
233
236
|
|
234
237
|
`Hoardable.save_trash` controls whether to create versions upon record deletion. When this is set to
|
235
238
|
`false`, all versions of a record will be deleted when the record is destroyed.
|
236
239
|
|
237
|
-
If you would like to temporarily set a config setting, you can use `Hoardable.with
|
240
|
+
If you would like to temporarily set a config setting, you can use `Hoardable.with`:
|
238
241
|
|
239
242
|
```ruby
|
240
243
|
Hoardable.with(enabled: false) do
|
@@ -242,6 +245,18 @@ Hoardable.with(enabled: false) do
|
|
242
245
|
end
|
243
246
|
```
|
244
247
|
|
248
|
+
You can also configure these variables per `ActiveRecord` class as well using `hoardable_options`:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
class Comment < ActiveRecord::Base
|
252
|
+
include Hoardable::Model
|
253
|
+
hoardable_options version_updates: false
|
254
|
+
end
|
255
|
+
```
|
256
|
+
|
257
|
+
If either the model-level option or global option for a configuration variable is set to `false`,
|
258
|
+
that behavior will be disabled.
|
259
|
+
|
245
260
|
### Relationships
|
246
261
|
|
247
262
|
As in life, sometimes relationships can be hard. `hoardable` is still working out best practices and
|
data/lib/hoardable/hoardable.rb
CHANGED
@@ -7,7 +7,7 @@ module Hoardable
|
|
7
7
|
DATA_KEYS = %i[meta whodunit note event_uuid].freeze
|
8
8
|
# Symbols for use with setting {Hoardable} configuration. See {file:README.md#configuration
|
9
9
|
# README} for more.
|
10
|
-
CONFIG_KEYS = %i[enabled save_trash].freeze
|
10
|
+
CONFIG_KEYS = %i[enabled version_updates save_trash].freeze
|
11
11
|
|
12
12
|
# @!visibility private
|
13
13
|
VERSION_CLASS_SUFFIX = 'Version'
|
@@ -15,9 +15,6 @@ module Hoardable
|
|
15
15
|
# @!visibility private
|
16
16
|
VERSION_TABLE_SUFFIX = "_#{VERSION_CLASS_SUFFIX.tableize}"
|
17
17
|
|
18
|
-
# @!visibility private
|
19
|
-
SAVE_TRASH_ENABLED = -> { Hoardable.save_trash }.freeze
|
20
|
-
|
21
18
|
# @!visibility private
|
22
19
|
DURING_QUERY = '_during @> ?::timestamp'
|
23
20
|
|
data/lib/hoardable/model.rb
CHANGED
@@ -8,6 +8,29 @@ module Hoardable
|
|
8
8
|
module Model
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
+
class_methods do
|
12
|
+
# @!visibility private
|
13
|
+
attr_reader :_hoardable_options
|
14
|
+
|
15
|
+
# If called with a hash, this will set the model-level +Hoardable+ configuration variables. If
|
16
|
+
# called without an argument it will return the computed +Hoardable+ configuration considering
|
17
|
+
# both model-level and global values.
|
18
|
+
#
|
19
|
+
# @param hash [Hash] The +Hoardable+ configuration for the model. Keys must be present in
|
20
|
+
# {CONFIG_KEYS}
|
21
|
+
# @return [Hash]
|
22
|
+
def hoardable_options(hash = nil)
|
23
|
+
if hash
|
24
|
+
@_hoardable_options = hash.slice(*Hoardable::CONFIG_KEYS)
|
25
|
+
else
|
26
|
+
@_hoardable_options ||= {}
|
27
|
+
Hoardable::CONFIG_KEYS.to_h do |key|
|
28
|
+
[key, Hoardable.send(key) != false && @_hoardable_options[key] != false]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
11
34
|
included do
|
12
35
|
define_model_callbacks :versioned
|
13
36
|
define_model_callbacks :reverted, only: :after
|
@@ -17,9 +17,9 @@ module Hoardable
|
|
17
17
|
included do
|
18
18
|
include Tableoid
|
19
19
|
|
20
|
-
around_update :insert_hoardable_version_on_update, if:
|
21
|
-
around_destroy :insert_hoardable_version_on_destroy, if: [
|
22
|
-
before_destroy :delete_hoardable_versions, if: :hoardable_callbacks_enabled, unless:
|
20
|
+
around_update :insert_hoardable_version_on_update, if: %i[hoardable_callbacks_enabled hoardable_version_updates]
|
21
|
+
around_destroy :insert_hoardable_version_on_destroy, if: %i[hoardable_callbacks_enabled hoardable_save_trash]
|
22
|
+
before_destroy :delete_hoardable_versions, if: :hoardable_callbacks_enabled, unless: :hoardable_save_trash
|
23
23
|
after_commit :unset_hoardable_version_and_event_uuid
|
24
24
|
|
25
25
|
# This will contain the +Version+ class instance for use within +versioned+, +reverted+, and
|
@@ -71,7 +71,15 @@ module Hoardable
|
|
71
71
|
private
|
72
72
|
|
73
73
|
def hoardable_callbacks_enabled
|
74
|
-
|
74
|
+
self.class.hoardable_options[:enabled] && !self.class.name.end_with?(VERSION_CLASS_SUFFIX)
|
75
|
+
end
|
76
|
+
|
77
|
+
def hoardable_save_trash
|
78
|
+
self.class.hoardable_options[:save_trash]
|
79
|
+
end
|
80
|
+
|
81
|
+
def hoardable_version_updates
|
82
|
+
self.class.hoardable_options[:version_updates]
|
75
83
|
end
|
76
84
|
|
77
85
|
def insert_hoardable_version_on_update(&block)
|
data/lib/hoardable/version.rb
CHANGED
data/sig/hoardable.rbs
CHANGED
@@ -1,4 +1,86 @@
|
|
1
1
|
module Hoardable
|
2
2
|
VERSION: String
|
3
|
-
|
3
|
+
DATA_KEYS: [:meta, :whodunit, :note, :event_uuid]
|
4
|
+
CONFIG_KEYS: [:enabled, :version_updates, :save_trash]
|
5
|
+
VERSION_CLASS_SUFFIX: String
|
6
|
+
VERSION_TABLE_SUFFIX: String
|
7
|
+
DURING_QUERY: String
|
8
|
+
self.@context: Hash[untyped, untyped]
|
9
|
+
self.@config: untyped
|
10
|
+
|
11
|
+
def self.with: (untyped hash) -> untyped
|
12
|
+
|
13
|
+
module Tableoid
|
14
|
+
TABLEOID_AREL_CONDITIONS: Proc
|
15
|
+
|
16
|
+
private
|
17
|
+
def tableoid: -> untyped
|
18
|
+
|
19
|
+
public
|
20
|
+
attr_writer tableoid: untyped
|
21
|
+
end
|
22
|
+
|
23
|
+
class Error < StandardError
|
24
|
+
end
|
25
|
+
|
26
|
+
module SourceModel
|
27
|
+
include Tableoid
|
28
|
+
|
29
|
+
def trashed?: -> untyped
|
30
|
+
def at: (untyped datetime) -> SourceModel
|
31
|
+
def revert_to!: (untyped datetime) -> SourceModel?
|
32
|
+
|
33
|
+
private
|
34
|
+
def hoardable_callbacks_enabled: -> untyped
|
35
|
+
def hoardable_save_trash: -> untyped
|
36
|
+
def hoardable_version_updates: -> untyped
|
37
|
+
def insert_hoardable_version_on_update: -> untyped
|
38
|
+
def insert_hoardable_version_on_destroy: -> untyped
|
39
|
+
def insert_hoardable_version: (String operation, untyped attrs) -> untyped
|
40
|
+
def find_or_initialize_hoardable_event_uuid: -> untyped
|
41
|
+
def initialize_hoardable_version: (String operation, untyped attrs) -> untyped
|
42
|
+
def initialize_hoardable_data: -> untyped
|
43
|
+
def assign_hoardable_context: (:event_uuid | :meta | :note | :whodunit key) -> nil
|
44
|
+
def delete_hoardable_versions: -> untyped
|
45
|
+
def unset_hoardable_version_and_event_uuid: -> nil
|
46
|
+
|
47
|
+
public
|
48
|
+
def version_class: -> untyped
|
49
|
+
attr_reader hoardable_version: nil
|
50
|
+
end
|
51
|
+
|
52
|
+
module VersionModel
|
53
|
+
@hoardable_source_attributes: untyped
|
54
|
+
@hoardable_source_foreign_key: String
|
55
|
+
@hoardable_source_foreign_id: untyped
|
56
|
+
|
57
|
+
def revert!: -> untyped
|
58
|
+
def untrash!: -> untyped
|
59
|
+
def changes: -> untyped
|
60
|
+
|
61
|
+
private
|
62
|
+
def untrashable_hoardable_source_attributes: -> untyped
|
63
|
+
def hoardable_source_attributes: -> untyped
|
64
|
+
def hoardable_source_foreign_key: -> String
|
65
|
+
def hoardable_source_foreign_id: -> untyped
|
66
|
+
def previous_temporal_tsrange_end: -> untyped
|
67
|
+
def assign_temporal_tsrange: -> Range
|
68
|
+
end
|
69
|
+
|
70
|
+
module Model
|
71
|
+
include VersionModel
|
72
|
+
include SourceModel
|
73
|
+
|
74
|
+
attr_reader _hoardable_options: Hash[untyped, untyped]
|
75
|
+
def hoardable_options: (?nil hash) -> untyped
|
76
|
+
end
|
77
|
+
|
78
|
+
class MigrationGenerator
|
79
|
+
@singularized_table_name: untyped
|
80
|
+
|
81
|
+
def create_versions_table: -> untyped
|
82
|
+
def foreign_key_type: -> String
|
83
|
+
def migration_template_name: -> String
|
84
|
+
def singularized_table_name: -> untyped
|
85
|
+
end
|
4
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoardable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- justin talbott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|