super_settings 2.1.2 → 2.2.1
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/CHANGELOG.md +12 -0
- data/VERSION +1 -1
- data/lib/super_settings/setting.rb +45 -9
- 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: f2db5de763e2b71a248913369bf05dda818d328fdee379a703054164ecdb9f51
|
4
|
+
data.tar.gz: 5ca7f24e706c33d4b79363144eb98e41c8772e046709f6fc2bc7f21ba91ea592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c45f9701cf13c981de225ea0fbe157709aab31cea37e967b33deeb0a9e382d2d0fe8e1a4afae889d572743f4bd40ad21e206ec6db34f74cff493c1a2560130
|
7
|
+
data.tar.gz: 5923794e1704cabf9885e6e7ff90420302158c77911efa9b47441a0d14c0e1326c0f0ca6699dc523898a08f0eb9375ceada0bf6414367eb5fa0995166ea2b1d5
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 2.2.1
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Added `SuperSettings::Setting#value_changed?` helper method to return true if the value of the setting has changed.
|
12
|
+
|
13
|
+
## 2.2.0
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- After save callbacks are now called only after the transaction is committed and settings have been persisted to the data store. When updating multiple records the callbacks will be called after all changes have been persisted rather than immediatly after calling `save!` on each record.
|
18
|
+
|
7
19
|
## 2.1.2
|
8
20
|
|
9
21
|
### Fixed
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1
|
1
|
+
2.2.1
|
@@ -164,7 +164,7 @@ module SuperSettings
|
|
164
164
|
all_valid, settings = update_settings(params, changed_by)
|
165
165
|
if all_valid
|
166
166
|
storage.with_connection do
|
167
|
-
|
167
|
+
transaction do |_changes|
|
168
168
|
settings.each do |setting|
|
169
169
|
setting.save!
|
170
170
|
end
|
@@ -202,6 +202,38 @@ module SuperSettings
|
|
202
202
|
cache&.delete(Setting::LAST_UPDATED_CACHE_KEY)
|
203
203
|
end
|
204
204
|
|
205
|
+
# Wrap a block of code in a transaction.
|
206
|
+
#
|
207
|
+
# @api private
|
208
|
+
def transaction(&block)
|
209
|
+
changes = Thread.current[:super_settings_transaction]
|
210
|
+
return yield if changes
|
211
|
+
|
212
|
+
changes = []
|
213
|
+
Thread.current[:super_settings_transaction] = changes
|
214
|
+
|
215
|
+
begin
|
216
|
+
@storage.transaction(&block)
|
217
|
+
|
218
|
+
clear_last_updated_cache
|
219
|
+
|
220
|
+
changes.each do |setting|
|
221
|
+
setting.send(:call_after_save_callbacks)
|
222
|
+
setting.send(:clear_changes)
|
223
|
+
end
|
224
|
+
ensure
|
225
|
+
Thread.current[:super_settings_transaction] = nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Add a record to the current transaction.
|
230
|
+
#
|
231
|
+
# @api private
|
232
|
+
def add_record_to_transaction(record)
|
233
|
+
changes = Thread.current[:super_settings_transaction]
|
234
|
+
changes << record if changes
|
235
|
+
end
|
236
|
+
|
205
237
|
private
|
206
238
|
|
207
239
|
# Updates settings in memory from an array of parameters.
|
@@ -454,17 +486,13 @@ module SuperSettings
|
|
454
486
|
self.created_at ||= timestamp
|
455
487
|
self.updated_at = timestamp if updated_at.nil? || !changed?(:updated_at)
|
456
488
|
|
489
|
+
return if @changes.empty?
|
490
|
+
|
457
491
|
self.class.storage.with_connection do
|
458
|
-
self.class.
|
492
|
+
self.class.transaction do
|
459
493
|
record_value_change
|
460
494
|
@record.save!
|
461
|
-
|
462
|
-
|
463
|
-
begin
|
464
|
-
self.class.clear_last_updated_cache
|
465
|
-
call_after_save_callbacks
|
466
|
-
ensure
|
467
|
-
clear_changes
|
495
|
+
self.class.add_record_to_transaction(self)
|
468
496
|
end
|
469
497
|
end
|
470
498
|
nil
|
@@ -547,6 +575,14 @@ module SuperSettings
|
|
547
575
|
@changes.dup
|
548
576
|
end
|
549
577
|
|
578
|
+
# Return true if the value of the setting has changed. In addition to changing the value,
|
579
|
+
# this will be triggered if the key changed or if the setting was marked as deleted.
|
580
|
+
#
|
581
|
+
# @return [Boolean]
|
582
|
+
def value_changed?
|
583
|
+
(@changes.keys & %w[key raw_value deleted]).any?
|
584
|
+
end
|
585
|
+
|
550
586
|
private
|
551
587
|
|
552
588
|
# Coerce a value for the appropriate value type.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|