model_timeline 0.1.4 → 0.1.6
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/lib/model_timeline/railtie.rb +4 -0
- data/lib/model_timeline/timelineable.rb +15 -14
- data/lib/model_timeline/version.rb +1 -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: 1c30cebe3384befbd1426f028e64ca6b35a39914a31aad9fc34205184b926ead
|
|
4
|
+
data.tar.gz: 9d7ed5bc145879fb09c6e664c2587c32c70f25266ac1c7a1db5b7fd11b128725
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47632a6615d0f07b8846c03825148c4d3222a81b9452d3e82116fe5e57c6fba72437a499ac315b1b3f8bd0b0b2358798a0f050c3d3f023afb7e994cf0a306fde
|
|
7
|
+
data.tar.gz: 050b15609e6b6cb2f9cbe08bf8939bf8b4f204b073049d42f847577f4bc235b3a5fa45dcc457412db4d15dca65aa1ca41720dc430deac0ccfa7433e36258a39a
|
|
@@ -20,8 +20,12 @@ module ModelTimeline
|
|
|
20
20
|
module Timelineable
|
|
21
21
|
extend ActiveSupport::Concern
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
def self.logger_store
|
|
24
|
+
@logger_store ||= {}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.clear_loggers!
|
|
28
|
+
logger_store.clear
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
# Methods that will be added as class methods to the including class
|
|
@@ -56,10 +60,6 @@ module ModelTimeline
|
|
|
56
60
|
# rubocop:disable Metrics/PerceivedComplexity
|
|
57
61
|
# rubocop:disable Naming/PredicateName
|
|
58
62
|
def has_timeline(*args, **kwargs)
|
|
59
|
-
if defined?(Rails.env) && Rails.env.development? && caller.any? { |line| line.include?('reload!') }
|
|
60
|
-
loggers.clear # Reset loggers during reload! in console
|
|
61
|
-
end
|
|
62
|
-
|
|
63
63
|
association_name = args.first.is_a?(Symbol) ? args.shift : :timeline_entries
|
|
64
64
|
|
|
65
65
|
klass = (kwargs[:class_name] || 'ModelTimeline::TimelineEntry').constantize
|
|
@@ -73,9 +73,9 @@ module ModelTimeline
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
config_key = "#{to_s.underscore}-#{klass}"
|
|
76
|
-
raise ::ModelTimeline::ConfigurationError if
|
|
76
|
+
raise ::ModelTimeline::ConfigurationError if ModelTimeline::Timelineable.logger_store[config_key].present?
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
ModelTimeline::Timelineable.logger_store[config_key] = config
|
|
79
79
|
|
|
80
80
|
after_save -> { log_after_save(config_key) } if config[:on].include?(:create) || config[:on].include?(:update)
|
|
81
81
|
|
|
@@ -97,15 +97,16 @@ module ModelTimeline
|
|
|
97
97
|
def log_after_save(config_key)
|
|
98
98
|
return unless ModelTimeline.enabled?
|
|
99
99
|
|
|
100
|
-
config =
|
|
100
|
+
config = ModelTimeline::Timelineable.logger_store[config_key]
|
|
101
101
|
return unless config
|
|
102
102
|
|
|
103
|
-
object_changes = filter_attributes(previous_changes, config)
|
|
104
|
-
return if object_changes.empty?
|
|
105
|
-
|
|
106
103
|
action = previously_new_record? ? :create : :update
|
|
107
104
|
return unless config[:on].include?(action)
|
|
108
105
|
|
|
106
|
+
current_changes = action == :create ? attributes.transform_values { |v| [nil, v] } : previous_changes
|
|
107
|
+
object_changes = filter_attributes(current_changes, config)
|
|
108
|
+
return if object_changes.empty?
|
|
109
|
+
|
|
109
110
|
config[:klass].create!(
|
|
110
111
|
timelineable_type: self.class.name,
|
|
111
112
|
timelineable_id: id,
|
|
@@ -125,14 +126,14 @@ module ModelTimeline
|
|
|
125
126
|
def log_audit_deletion(config_key)
|
|
126
127
|
return unless ModelTimeline.enabled?
|
|
127
128
|
|
|
128
|
-
config =
|
|
129
|
+
config = ModelTimeline::Timelineable.logger_store[config_key]
|
|
129
130
|
return unless config
|
|
130
131
|
|
|
131
132
|
config[:klass].create!(
|
|
132
133
|
timelineable_type: self.class.name,
|
|
133
134
|
timelineable_id: id,
|
|
134
135
|
action: 'destroy',
|
|
135
|
-
object_changes: attributes.transform_values { |v| [v, nil] },
|
|
136
|
+
object_changes: filter_attributes(attributes.transform_values { |v| [v, nil] }, config),
|
|
136
137
|
metadata: object_metadata(config),
|
|
137
138
|
ip_address: current_ip_address,
|
|
138
139
|
**current_user_attributes,
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: model_timeline
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandre Stapenhorst
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-06-
|
|
11
|
+
date: 2025-06-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|