ms_rest 0.7.1 → 0.7.2

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
  SHA1:
3
- metadata.gz: 275e752a1faf000ce807e83bbdc94b4ebdcffa90
4
- data.tar.gz: 26dfb95c46525129becb89832d11b7d1eaef541f
3
+ metadata.gz: 6e955b7950efa77e049373a0428100865d18b26d
4
+ data.tar.gz: 4f76d46ad6a6fda8531608e7857c9174704c0f25
5
5
  SHA512:
6
- metadata.gz: ee97540dfe67881418cff39a852149941515107490d559caaf729aefe836bb1c2d4c585fa6df245b56744541db4196d54f1faaa71826e3232359bddb0baf13ad
7
- data.tar.gz: a41324d4c4a4cbeded367b1f0e239e31335ac3fe3532858ba804c038bc5cd87d01f4cc31e9ef75d1f78f3df8256871711342e5d660f76dc542d49d97347b60af
6
+ metadata.gz: f725c74997de1043afd9427051a9f06100988425619405f0f5e2559873ba481bb9105822e3122be8c52fc7602b8b8cac809526a5beb70f3381ceb23a7a19ae85
7
+ data.tar.gz: 9cb2186ad4370277882abe7a9d57de7f513892b219b3c0a48b4ee84a1ba794b664786aed41c2006835400408b5c7d134067c87ea1313ed096d4d63ea3fd348ab
@@ -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.0'
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
- # Throw if required & non-constant object is nil
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
  #
@@ -3,5 +3,5 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for license information.
4
4
 
5
5
  module MsRest
6
- VERSION = '0.7.1'
6
+ VERSION = '0.7.2'
7
7
  end
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.1
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-07-27 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler