ultra_settings 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a34c970ed06134a778e29f09ef7640a255a82f45bbf74e703963a7d9b911b598
4
- data.tar.gz: 8065a6941af25b2d18b0e6617af074443c4de7da24541fad0d062f562a640c4d
3
+ metadata.gz: 2a9fddef64ed0564d8ead06ae79465a37fdb50a55407139cacc121714475ac6f
4
+ data.tar.gz: a26020c7d81154d3e000bba327e3a6cb53ab00ae9847ed2f96999ff18d431241
5
5
  SHA512:
6
- metadata.gz: d740cea45e6d52bf0392f9c867661b24b55f01ed0b3bb557f9730876af973d08036a47197539cee655a584a11b07b3ecb7ffcbd51cf4a6032605c9ab59b9277b
7
- data.tar.gz: f11544c978f8b17790d9fe50b5fb03338a680da9dd4e045cc6e45cad2ab5e6910b51c737fd2735052eb835232023707dbd93bb6460627376765c01779c1f099f
6
+ metadata.gz: 066b922fcc7232a33eee6e6b52924d1efc51d3a4e500f4680f8e03a1feb7a6414a22b55f9b5672e35db7aeb958566fc1685ba39fed8a9f568840af2b60a7b3e2
7
+ data.tar.gz: b95942f92c5010decb55da413fdd2c9f070ebafef2815ab5bd4f781f803b744c502b98598fc14b4e5338ec7026fd7a1c5b11011136afe4507a0eeb436dac632b
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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.0
8
+
9
+ ### Added
10
+
11
+ - Added logic for parsing arrays from environment variables. Array fields can now be set as comma delimited strings in an environment variable.
12
+
13
+ ### Fixed
14
+
15
+ - Mixed case boolean values are now handled properly so that "False" is interpreted as `false` and "True" is interpreted as `true`.
16
+
7
17
  ## 2.2.0
8
18
 
9
19
  ### Added
data/README.md CHANGED
@@ -100,13 +100,13 @@ You can customize the behavior of each field using various options:
100
100
 
101
101
  - `:type` - Specifies the type of the field. The value of the setting will be cast to this type. If the value in the data source cannot be cast to the data type, then it will not be used. Supported types are:
102
102
 
103
- - `:string` (the default)
103
+ - `:string` - This is the default type.
104
104
  - `:integer`
105
105
  - `:float`
106
- - `:boolean` (will accept case insensitive strings "true", "false", "1", "0", "t", "f", "yes", "no", "y", "n")
107
- - `:datetime`
106
+ - `:boolean` - Will accept case insensitive strings "true", "false", "1", "0", "t", "f", "yes", "no", "y", "n".
107
+ - `:datetime` - Values should be specified in ISO 8601 format.
108
108
  - `:symbol`
109
- - `:array` (of strings)
109
+ - `:array` - The array type will return an array of strings. If the raw value is a string (i.e. from an environment variable), it will be iterpreted as a comma separated list of values. You can use double quotes to group values that contain commas and backslashes to escape values. Leading and trailing whitespace will be stripped from each value.
110
110
 
111
111
  - `:description` - Provides a description of the field. This is used for documentation purposes.
112
112
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
@@ -10,11 +10,8 @@ module UltraSettings
10
10
  false, 0,
11
11
  "0", :"0",
12
12
  "f", :f,
13
- "F", :F,
14
13
  "false", :false,
15
- "FALSE", :FALSE,
16
- "off", :off,
17
- "OFF", :OFF
14
+ "off", :off
18
15
  ]).freeze
19
16
  # rubocop:enable Lint/BooleanSymbol
20
17
 
@@ -39,7 +36,7 @@ module UltraSettings
39
36
  when :datetime
40
37
  time(value)
41
38
  when :array
42
- Array(value).map(&:to_s)
39
+ array(value).map(&:to_s)
43
40
  when :symbol
44
41
  value.to_s.to_sym
45
42
  when :rollout
@@ -53,14 +50,26 @@ module UltraSettings
53
50
  end
54
51
  end
55
52
 
53
+ # Cast value of array
54
+ #
55
+ # @param value [Object]
56
+ # @return [Array]
57
+ def array(value)
58
+ return [] if blank?(value)
59
+ return value.collect(&:to_s) if value.is_a?(Array)
60
+
61
+ parse_csv_line(value.to_s)
62
+ end
63
+
56
64
  # Cast variations of booleans (i.e. "true", "false", 1, 0, etc.) to actual boolean objects.
57
65
  #
58
66
  # @param value [Object]
59
67
  # @return [Boolean]
60
68
  def boolean(value)
61
69
  return nil if blank?(value)
70
+ return false if value == false
62
71
 
63
- !FALSE_VALUES.include?(value)
72
+ !FALSE_VALUES.include?(value.to_s.downcase)
64
73
  end
65
74
 
66
75
  # Cast a value to a Time object.
@@ -104,6 +113,43 @@ module UltraSettings
104
113
  def present?(value)
105
114
  !blank?(value)
106
115
  end
116
+
117
+ private
118
+
119
+ # Parse a line of CSV data to an array of strings. Elements are separated by commas and
120
+ # characters can be escaped with a backslash.
121
+ def parse_csv_line(line)
122
+ values = []
123
+ current_value = +""
124
+ in_quotes = false
125
+
126
+ i = 0
127
+ while i < line.length
128
+ char = line[i]
129
+
130
+ if char == "\\"
131
+ if i + 1 < line.length
132
+ current_value << line[i + 1]
133
+ i += 1
134
+ else
135
+ current_value << "\\"
136
+ end
137
+ elsif char == '"'
138
+ in_quotes = !in_quotes
139
+ elsif char == "," && !in_quotes
140
+ values << current_value.strip
141
+ current_value = +""
142
+ else
143
+ current_value << char
144
+ end
145
+
146
+ i += 1
147
+ end
148
+
149
+ values << current_value.strip unless current_value.empty?
150
+
151
+ values
152
+ end
107
153
  end
108
154
  end
109
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
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-10-28 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler