ms_rest 0.7.1 → 0.7.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/ms_rest/serialization.rb +39 -4
- data/lib/ms_rest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e955b7950efa77e049373a0428100865d18b26d
|
4
|
+
data.tar.gz: 4f76d46ad6a6fda8531608e7857c9174704c0f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f725c74997de1043afd9427051a9f06100988425619405f0f5e2559873ba481bb9105822e3122be8c52fc7602b8b8cac809526a5beb70f3381ceb23a7a19ae85
|
7
|
+
data.tar.gz: 9cb2186ad4370277882abe7a9d57de7f513892b219b3c0a48b4ee84a1ba794b664786aed41c2006835400408b5c7d134067c87ea1313ed096d4d63ea3fd348ab
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
##2017.11.10 ms_rest version 0.7.2
|
2
|
+
* [Enhancement] Added code to check & validate the constraints on the model. Refer [PR #1119](https://github.com/Azure/azure-sdk-for-ruby/pull/1119/files) for more details.
|
3
|
+
|
1
4
|
##2017.07.27 ms_rest version 0.7.1
|
2
5
|
* [Bug Fix] Modified to_json logic in JSONable module to handle 'mapper' & 'object' options.[PR #860](https://github.com/Azure/azure-sdk-for-ruby/pull/860)
|
3
6
|
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ To start working on the gem the only additional dev dependency is required - rsp
|
|
48
48
|
Reference it in the gemfile and also add this line to your client's gemspec file:
|
49
49
|
|
50
50
|
```ruby
|
51
|
-
spec.add_runtime_dependency 'ms_rest', '~> 0.7.
|
51
|
+
spec.add_runtime_dependency 'ms_rest', '~> 0.7.2'
|
52
52
|
```
|
53
53
|
Don't forget to correct the version.
|
54
54
|
|
@@ -221,10 +221,7 @@ module MsRest
|
|
221
221
|
end
|
222
222
|
object = mapper[:default_value] if mapper[:is_constant]
|
223
223
|
|
224
|
-
|
225
|
-
if mapper[:required] && object.nil? && !mapper[:is_constant]
|
226
|
-
fail ValidationError, "#{object_name} is required and cannot be nil"
|
227
|
-
end
|
224
|
+
validate_constraints(mapper, object, object_name)
|
228
225
|
|
229
226
|
if !mapper[:required] && object.nil?
|
230
227
|
return object
|
@@ -244,6 +241,44 @@ module MsRest
|
|
244
241
|
payload
|
245
242
|
end
|
246
243
|
|
244
|
+
def validate_constraints(mapper, object, object_name)
|
245
|
+
if(mapper[:client_side_validation])
|
246
|
+
# Throw if required & non-constant object is nil
|
247
|
+
if mapper[:required] && object.nil? && !mapper[:is_constant]
|
248
|
+
fail ValidationError, "#{object_name} is required and cannot be nil"
|
249
|
+
end
|
250
|
+
|
251
|
+
if(mapper[:constraints])
|
252
|
+
mapper[:constraints].each do |constraint_name, constraint_value|
|
253
|
+
case constraint_name.to_s.downcase
|
254
|
+
when 'exclusivemaximum'
|
255
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'ExclusiveMaximum': '#{constraint_value}'" if !object.nil? && object >= constraint_value
|
256
|
+
when 'exclusiveminimum'
|
257
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'ExclusiveMinimum': '#{constraint_value}'" if !object.nil? && object <= constraint_value
|
258
|
+
when 'inclusivemaximum'
|
259
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'InclusiveMaximum': '#{constraint_value}'" if !object.nil? && object > constraint_value
|
260
|
+
when 'inclusiveminimum'
|
261
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'InclusiveMinimum': '#{constraint_value}'" if !object.nil? && object < constraint_value
|
262
|
+
when 'maxitems'
|
263
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'MaxItems': '#{constraint_value}'" if !object.nil? && object.length > constraint_value
|
264
|
+
when 'minitems'
|
265
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'MinItems': '#{constraint_value}'" if !object.nil? && object.length < constraint_value
|
266
|
+
when 'maxlength'
|
267
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'MaxLength': '#{constraint_value}'" if !object.nil? && object.length > constraint_value
|
268
|
+
when 'minlength'
|
269
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'MinLength': '#{constraint_value}'" if !object.nil? && object.length < constraint_value
|
270
|
+
when 'multipleof'
|
271
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'MultipleOf': '#{constraint_value}'" if !object.nil? && object % constraint_value != 0
|
272
|
+
when 'pattern'
|
273
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'Pattern': '#{constraint_value}'" if !object.nil? && object.match(Regexp.new "^#{constraint_value}$").nil?
|
274
|
+
when 'uniqueitems'
|
275
|
+
fail ValidationError, "#{object_name} with value '#{object}' should satisfy the constraint 'UniqueItems': '#{constraint_value}'" if !object.nil? && object.length != object.uniq.length
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
247
282
|
#
|
248
283
|
# Serialize the Ruby object of known primary type into Ruby Hash to send it to the server using the mapper.
|
249
284
|
#
|
data/lib/ms_rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ms_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Microsoft Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|