super_settings 2.2.1 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2db5de763e2b71a248913369bf05dda818d328fdee379a703054164ecdb9f51
4
- data.tar.gz: 5ca7f24e706c33d4b79363144eb98e41c8772e046709f6fc2bc7f21ba91ea592
3
+ metadata.gz: a8062539b6606b9cd5d043cfe7ec52abfe7a49a13edb59fbd8a9660831282c89
4
+ data.tar.gz: 5bd8d1a568fc9828f0a3c1d57d2efda2109ffebf7ecbe5ba55d8ba1c01e1f57c
5
5
  SHA512:
6
- metadata.gz: c3c45f9701cf13c981de225ea0fbe157709aab31cea37e967b33deeb0a9e382d2d0fe8e1a4afae889d572743f4bd40ad21e206ec6db34f74cff493c1a2560130
7
- data.tar.gz: 5923794e1704cabf9885e6e7ff90420302158c77911efa9b47441a0d14c0e1326c0f0ca6699dc523898a08f0eb9375ceada0bf6414367eb5fa0995166ea2b1d5
6
+ metadata.gz: e0a64b3993479ec0f0e94ba362e9dba51dd2ca44d2da8ec09c29f2e0a67bbcae4393352846de727cd21c31eab244304edf8847d2d922acd583cc6f4dc9ebc482
7
+ data.tar.gz: 65952c3cecf4ef4c97ff4d84e0a6d49ee4515260551c6941dbe8eeaf894bf3a0d21c922ed8d6afb8431680556c39771de93656de31f1f7c8fa2ef4dd5b84f3ef
data/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ 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.3.1
8
+
9
+ ### Fixed
10
+
11
+ - Add check if database connection is valid for ActiveRecord storage engine to avoid race conditions where settings were not available until an application model was used.
12
+
13
+ ## 2.3.0
14
+
15
+ ### Changed
16
+
17
+ - Calling `SuperSettings.get` on a setting stored as an array now returns the array as a multiline string rather than simply calling `to_s` on the array. So an array setting stored as `["foo", "bar"]` will now be returned as `"foo\nbar"` rather than `'["foo", "bar"]'`.
18
+ - Calling `SuperSettings.get` on a setting stored as a datetime will now return the value as an ISO-8601 formatted string rather than simply calling `to_s` on the `Time` object.
19
+
7
20
  ## 2.2.1
8
21
 
9
22
  ### Added
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.3.1
@@ -34,7 +34,7 @@ module SuperSettings
34
34
  # @param value [Object]
35
35
  # @return [Time]
36
36
  def time(value)
37
- value = nil if value.nil? || value.to_s.empty?
37
+ value = nil if blank?(value)
38
38
  return nil if value.nil?
39
39
 
40
40
  time = if value.is_a?(Numeric)
@@ -50,6 +50,25 @@ module SuperSettings
50
50
  time
51
51
  end
52
52
 
53
+ # Cast a value to a string.
54
+ #
55
+ # @param value [Object]
56
+ # @return [String]
57
+ def string(value)
58
+ value = nil if blank?(value)
59
+ return nil if value.nil?
60
+
61
+ if value.is_a?(String)
62
+ value
63
+ elsif value.is_a?(Array)
64
+ value.join("\n")
65
+ elsif value.respond_to?(:iso8601)
66
+ value.iso8601
67
+ else
68
+ value.to_s
69
+ end
70
+ end
71
+
53
72
  # @return [Boolean] true if the value is nil or empty.
54
73
  def blank?(value)
55
74
  return true if value.nil?
@@ -16,8 +16,29 @@ module SuperSettings
16
16
  class << self
17
17
  # ActiveRecord storage is only available if the connection pool is connected and the table exists.
18
18
  def available?
19
+ attempt_connection!
19
20
  connection_pool&.connected? && table_exists?
20
21
  end
22
+
23
+ private
24
+
25
+ @connection_attempted = false
26
+
27
+ def attempt_connection!
28
+ return if @connection_attempted
29
+
30
+ @connection_attempted = true
31
+ return if connection_pool.nil? || connection_pool.connected?
32
+
33
+ begin
34
+ connection_pool.with_connection do
35
+ # Do nothing, just ensure that the connection is established.
36
+ end
37
+ rescue ActiveRecord::ConnectionNotEstablished
38
+ # Ignore errors so the application doesn't break if the database is not available.
39
+ # Otherwise things like build processes can fail.
40
+ end
41
+ end
21
42
  end
22
43
  end
23
44
 
@@ -35,7 +35,10 @@ module SuperSettings
35
35
  # @return [String]
36
36
  def get(key, default = nil)
37
37
  val = context_setting(key)
38
- val.nil? ? default : val.to_s
38
+ return val if val.is_a?(String)
39
+ return default if val.nil?
40
+
41
+ Coerce.string(val)
39
42
  end
40
43
 
41
44
  # Alias for {#get} to allow using the [] operator to get a setting value.
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.2.1
4
+ version: 2.3.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-05 00:00:00.000000000 Z
11
+ date: 2025-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler