saphyr 0.6.0 → 0.6.2

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: 9d491ec052216eb7db303fa4fb65b6a558ecbb2c39a24663a43ae85eb616da14
4
- data.tar.gz: a07b8137c7e853c0e9625a18760139a220a1be4fdf5271365f81cd2459e288a5
3
+ metadata.gz: 3c7defd833657907234635898b8a7670ebe18201220ad4c09ece8244d9740525
4
+ data.tar.gz: e6cd62b82709f9adae9e680d274e1af4c3715c986b98273b09ad67ed75cac0fa
5
5
  SHA512:
6
- metadata.gz: a816ea8a58c18ae02e599f077f40ce54081e84e8a12ea47e9e3734ce410e238c2562105bc4fd55cf9facfba94477d5856cf708877514eb369f5ffdd85413d7f1
7
- data.tar.gz: bf4a796653f788a49f80bb2b1344d87a059e20a98c8fbd9ed8cd87d13062c228c153c62a8097204f252e69157611cd6d59b6b36b601fbd566b8a9bd0a8c24ff5
6
+ metadata.gz: f5e7b9d8ce9886b15b8053d497f48cbfb76d476b89f8651a53bbbf472e13d8df2b87cfb7afe059eaf67e11292ae2c8296e56ea082177c80e5e03b46aaf9a0ca8
7
+ data.tar.gz: 4f994fd60eed366205152a38967e59aabe6505f6e710da190d79325ad283aa482c192d7a24323e60129484019ee4238042d2d4e8a644cb163c17207aafa59a28
data/CHANGELOG CHANGED
@@ -1,3 +1,23 @@
1
+ -----------------------------------------------------------------
2
+ Version: 0.6.2 - 2026-07-17
3
+
4
+ - Fix CVE-2026-41493 and CVE-2026-49342 upgrade yard to ~> 0.9.45
5
+
6
+ -----------------------------------------------------------------
7
+ Version: 0.6.1 - 2025-06-29
8
+
9
+ - Refactor email_field to use assert_string_regexp
10
+ - Make get() variadic to fetch deep fields
11
+ - Add get_safe()
12
+
13
+ -----------------------------------------------------------------
14
+ Version: 0.6.0 - 2025-06-21
15
+
16
+ - Add standard field types
17
+ Email, URI, URL, Base64, ipv4, ipv6, ISO Country, ISO Language
18
+ - Add assert_not_empty
19
+ - Refactor expected_types()
20
+
1
21
  -----------------------------------------------------------------
2
22
  Version: 0.5.0 - 2025-05-21
3
23
 
@@ -14,14 +14,7 @@ module Saphyr
14
14
 
15
15
  def do_validate(ctx, name, value, errors)
16
16
  return unless assert_not_empty value, errors
17
- unless value =~ ::URI::MailTo::EMAIL_REGEXP
18
- errors << {
19
- type: err('invalid'),
20
- data: {
21
- _val: value
22
- }
23
- }
24
- end
17
+ assert_string_regexp ::URI::MailTo::EMAIL_REGEXP, value, errors
25
18
  end
26
19
  end
27
20
  end
@@ -119,11 +119,80 @@ module Saphyr
119
119
  end
120
120
 
121
121
  # Get a field from the data to validate.
122
- # @param field [String | Symbol] The field name
122
+ #
123
+ # Use variadic arguments to access deep fields.
124
+ #
125
+ # Examples:
126
+ #
127
+ # data = {
128
+ # "id" => 3465,
129
+ # "info" => {
130
+ # "suffix" => ["gif", "jpg", "png"]
131
+ # "size" => 34056
132
+ # }
133
+ # }
134
+ #
135
+ # get("id") # => 3435
136
+ # get("info", "suffix", 1) # => "jpg"
137
+ # get("info", "size") # => 34056
138
+ # get("name") # => raise an exception
139
+ #
123
140
  # @return The field value
124
- def get(field)
125
- data = @ctx.data_to_validate
126
- data[field.to_s]
141
+ # @raise [Saphyr::Error] If field does not exists.
142
+ def get(*args)
143
+ status, value = get_safe(*args)
144
+ raise Saphyr::Error.new 'Requested field does not exists' if status == :err
145
+ value
146
+ end
147
+
148
+ # Get a field from the data to validate.
149
+ # (Same as +get()+ but never raise an exception).
150
+ #
151
+ # Use variadic arguments to access deep fields.
152
+ #
153
+ # Examples:
154
+ #
155
+ # data = {
156
+ # "id" => 3465,
157
+ # "info" => {
158
+ # "suffix" => ["gif", "jpg", "png"]
159
+ # "size" => 34056
160
+ # }
161
+ # }
162
+ #
163
+ # get("id") # => [:ok, 3435]
164
+ # get("info", "suffix", 1) # => [:ok, "jpg"]
165
+ # get("info", "size") # => [:ok, 34056]
166
+ # get("name") # => [:err, :not_exists]
167
+ # get("info", "suffix", 5) # => [:err, :not_index]
168
+ # get("info", 3) # => [:err, :not_array]
169
+ #
170
+ # @return An array where first element is the status and second element is the result.
171
+ def get_safe(*args)
172
+ do_get_safe @data, args.reverse
173
+ end
174
+
175
+ private
176
+
177
+ def do_get_safe(data, args)
178
+ return [:ok, data] if args.size == 0
179
+ key = args.pop
180
+ if data.is_a? Hash
181
+ key = key.to_s if key.is_a? Symbol
182
+ if data.key? key
183
+ return do_get_safe data[key], args
184
+ else
185
+ return [:err, :not_exists]
186
+ end
187
+ elsif data.is_a? Array
188
+ if key.is_a? Integer
189
+ return do_get_safe data[key], args
190
+ else
191
+ return [:err, :not_index]
192
+ end
193
+ else
194
+ return [:err, :not_array]
195
+ end
127
196
  end
128
197
  end
129
198
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Saphyr
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saphyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - odelbos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-20 00:00:00.000000000 Z
11
+ date: 2026-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
- description: The purpose of Saphyr is to provide a nice and simple DSL to easily and
42
- quickly design a validation schema for JSON document.
41
+ description: Simple DSL to design validation schemas for JSON document (or Hash /
42
+ Array structure)
43
43
  email:
44
44
  - od@phibox.com
45
45
  executables: []
@@ -111,5 +111,6 @@ requirements: []
111
111
  rubygems_version: 3.5.6
112
112
  signing_key:
113
113
  specification_version: 4
114
- summary: The saphyr gem is used to validate JSON document.
114
+ summary: Simple DSL to design validation schemas for JSON document (or Hash / Array
115
+ structure)
115
116
  test_files: []