model_timeline 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11d959076d546ea778aaad610afaf48458725f4c9dbc8f46148de1f137f31604
4
- data.tar.gz: 5f6a6d3321e2277690d06b84bae0aebb3c3d1cde1f0760b26ae444d100151428
3
+ metadata.gz: d9b06a537daa1e546effd75438c323e45060d950bde291820a0e04365dac9282
4
+ data.tar.gz: f691d5563a5da5ff7d6871e99025b6c0bee18ad5dd0bbeaaec428335cfb258a0
5
5
  SHA512:
6
- metadata.gz: 9224951a8e3958ef129b183f7c9535485e3c085d85aca91169c303f7443a2f79fba9906c5a4d5897f708edc73a8ac4efc5661391ae609e2da91a9fa000f856a5
7
- data.tar.gz: 54928db8b6fb566b047379dc21227f2388b2fe67e0f1b07ddf0410ed124d57428a6adedf3e726d83c14f7aec1f0837f95ce13adbe20b4295a4280d36794d3942
6
+ metadata.gz: e0d0b6345364466a0145064b690888f50817cd81f9bbc3745cff3e732cf59377e3cad27bd32f6a1ffa4b9a1051385f398b6db86e3e2e631d6170c3de849c1078
7
+ data.tar.gz: dff77944a1c78176c7c84a32b41efe282648ca1ca091c83823563ed81a3b58ea41ab6068cc3f879028b99375f9e25863d92abe11c82b051ebd589349b9741e02
@@ -26,6 +26,10 @@ module ModelTimeline
26
26
  ActiveSupport.on_load(:action_controller) do
27
27
  include ControllerAdditions::ClassMethods
28
28
  end
29
+
30
+ config.to_prepare do
31
+ ModelTimeline::Timelineable.clear_loggers!
32
+ end
29
33
  end
30
34
  end
31
35
  end
@@ -20,8 +20,12 @@ module ModelTimeline
20
20
  module Timelineable
21
21
  extend ActiveSupport::Concern
22
22
 
23
- included do
24
- class_attribute :loggers, default: {}
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 loggers[config_key].present?
76
+ raise ::ModelTimeline::ConfigurationError if ModelTimeline::Timelineable.logger_store[config_key].present?
77
77
 
78
- loggers[config_key] = config
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,7 +97,7 @@ module ModelTimeline
97
97
  def log_after_save(config_key)
98
98
  return unless ModelTimeline.enabled?
99
99
 
100
- config = self.class.loggers[config_key]
100
+ config = ModelTimeline::Timelineable.logger_store[config_key]
101
101
  return unless config
102
102
 
103
103
  object_changes = filter_attributes(previous_changes, config)
@@ -125,14 +125,14 @@ module ModelTimeline
125
125
  def log_audit_deletion(config_key)
126
126
  return unless ModelTimeline.enabled?
127
127
 
128
- config = self.class.loggers[config_key]
128
+ config = ModelTimeline::Timelineable.logger_store[config_key]
129
129
  return unless config
130
130
 
131
131
  config[:klass].create!(
132
132
  timelineable_type: self.class.name,
133
133
  timelineable_id: id,
134
134
  action: 'destroy',
135
- object_changes: {},
135
+ object_changes: attributes.transform_values { |v| [v, nil] },
136
136
  metadata: object_metadata(config),
137
137
  ip_address: current_ip_address,
138
138
  **current_user_attributes,
@@ -5,5 +5,5 @@ module ModelTimeline
5
5
  # Follows semantic versioning (https://semver.org/).
6
6
  #
7
7
  # @return [String] The current version in the format "MAJOR.MINOR.PATCH"
8
- VERSION = '0.1.3'
8
+ VERSION = '0.1.5'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_timeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Stapenhorst