ms_rest 0.6.4 → 0.7.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
  SHA1:
3
- metadata.gz: 557c3c233a2d26e6bd39063c570ab562ed7fc98b
4
- data.tar.gz: ee941f9448f40926491505a0bc5e5d3ff018b5fb
3
+ metadata.gz: 6002241e297f352e09b8b7e66ccccf2c6dd11817
4
+ data.tar.gz: f4326806d9a7ef67e857d06ef40f1dc54c6fa418
5
5
  SHA512:
6
- metadata.gz: 5ea7bb73cf7dccc48a7d43187c7e7b0034d0b22bacfd93c824b7016fdbbc5ea90be2754e594140311819a935587bac3983c34c9addc365fd6e4f445a7f6b94fc
7
- data.tar.gz: 930bfd23cbfbd0ebbb24f84557744efa637b127d86139584777e7f803eee2da55d685144642d119b85abb763896f062a238920ae869df91b1028a39a971b7da9
6
+ metadata.gz: 3b9dda5a36648483b1ba2c4c12de38e3942ce32abe051b7f997c1742808b28115431ead4b5e20000a9b61fad3cba7b454957a0494bc8248ff2d3d2bb528ffaac
7
+ data.tar.gz: 97abece3a32d63a121cd3a47656af95045efe319e12efca496939a0a8d6444aaa42c297a89cfda64db8117b06bcf2cebaa26225b5db57db2bc475f545c22fc1f
@@ -1,3 +1,6 @@
1
+ ##2017.06.30 ms_rest version 0.7.0
2
+ * [Breaking Change] Refactored serialization & deserialization logic to remove client from the process.[Issue #610](https://github.com/Azure/azure-sdk-for-ruby/issues/610) [PR #799](https://github.com/Azure/azure-sdk-for-ruby/pull/799)
3
+
1
4
  ##2017.04.04 ms_rest version 0.6.4
2
5
  * Bug fix to handle new faraday version. [Issue #182](https://github.com/Azure/vagrant-azure/issues/182)
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.6.4'
51
+ spec.add_runtime_dependency 'ms_rest', '~> 0.7.0'
52
52
  ```
53
53
  Don't forget to correct the version.
54
54
 
@@ -9,10 +9,12 @@ module MsRest
9
9
 
10
10
  #
11
11
  # Serialize the object to JSON
12
+ # @param options [Hash] hash map contains options to convert to json.
12
13
  # @return [String] JSON serialized version of the object
13
14
  #
14
- def to_json
15
- serialize(self.class.mapper, self)
15
+ def to_json(options = nil)
16
+ mapper = self.class.mapper if options.nil? || !options.key?(:mapper)
17
+ serialize(mapper, self)
16
18
  end
17
19
 
18
20
  #
@@ -20,8 +22,9 @@ module MsRest
20
22
  # @param json [String] JSON string representation of the object
21
23
  # @return [JSONable] object built from json input
22
24
  #
23
- def from_json(json)
24
- deserialize(self.class.mapper, json)
25
+ def from_json(json, mapper = nil)
26
+ mapper = self.class.mapper if mapper.nil?
27
+ deserialize(mapper, json)
25
28
  end
26
29
 
27
30
  #
@@ -15,8 +15,8 @@ module MsRest
15
15
  # @param response_body [Hash] Ruby Hash object to deserialize.
16
16
  # @param object_name [String] Name of the deserialized object.
17
17
  #
18
- def deserialize(mapper, response_body, object_name = nil)
19
- build_serializer.deserialize(mapper, response_body, object_name)
18
+ def deserialize(mapper, response_body)
19
+ build_serializer.deserialize(mapper, response_body)
20
20
  end
21
21
 
22
22
  #
@@ -26,8 +26,8 @@ module MsRest
26
26
  # @param object [Object] Ruby object to serialize.
27
27
  # @param object_name [String] Name of the serialized object.
28
28
  #
29
- def serialize(mapper, object, object_name = nil)
30
- build_serializer.serialize(mapper, object, object_name)
29
+ def serialize(mapper, object)
30
+ build_serializer.serialize(mapper, object)
31
31
  end
32
32
 
33
33
  private
@@ -54,10 +54,10 @@ module MsRest
54
54
  # @param response_body [Hash] Ruby Hash object to deserialize.
55
55
  # @param object_name [String] Name of the deserialized object.
56
56
  #
57
- def deserialize(mapper, response_body, object_name)
57
+ def deserialize(mapper, response_body)
58
58
  return response_body if response_body.nil?
59
59
 
60
- object_name = mapper[:serialized_name] unless object_name.nil?
60
+ object_name = mapper[:serialized_name]
61
61
  mapper_type = mapper[:type][:name]
62
62
 
63
63
  if !mapper_type.match(/^(Number|Double|ByteArray|Boolean|Date|DateTime|DateTimeRfc1123|UnixTime|Enum|String|Object|Stream)$/i).nil?
@@ -131,7 +131,7 @@ module MsRest
131
131
 
132
132
  result = Hash.new
133
133
  response_body.each do |key, val|
134
- result[key] = deserialize(mapper[:type][:value], val, object_name)
134
+ result[key] = deserialize(mapper[:type][:value], val)
135
135
  end
136
136
  result
137
137
  end
@@ -177,7 +177,7 @@ module MsRest
177
177
  levels.each { |level| sub_response_body = sub_response_body.nil? ? nil : sub_response_body[level.to_s] }
178
178
  end
179
179
 
180
- result.instance_variable_set("@#{key}", deserialize(val, sub_response_body, object_name)) unless sub_response_body.nil?
180
+ result.instance_variable_set("@#{key}", deserialize(val, sub_response_body)) unless sub_response_body.nil?
181
181
  end
182
182
  end
183
183
  result
@@ -199,7 +199,7 @@ module MsRest
199
199
 
200
200
  result = []
201
201
  response_body.each do |element|
202
- result.push(deserialize(mapper[:type][:element], element, object_name))
202
+ result.push(deserialize(mapper[:type][:element], element))
203
203
  end
204
204
 
205
205
  result
@@ -212,8 +212,8 @@ module MsRest
212
212
  # @param object [Object] Ruby object to serialize.
213
213
  # @param object_name [String] Name of the serialized object.
214
214
  #
215
- def serialize(mapper, object, object_name)
216
- object_name = mapper[:serialized_name] unless object_name.nil?
215
+ def serialize(mapper, object)
216
+ object_name = mapper[:serialized_name]
217
217
 
218
218
  # Set defaults
219
219
  unless mapper[:default_value].nil?
@@ -297,7 +297,7 @@ module MsRest
297
297
  value.validate
298
298
  end
299
299
 
300
- payload[key] = serialize(mapper[:type][:value], value, object_name)
300
+ payload[key] = serialize(mapper[:type][:value], value)
301
301
  end
302
302
  payload
303
303
  end
@@ -339,7 +339,7 @@ module MsRest
339
339
  next
340
340
  end
341
341
 
342
- sub_payload = serialize(value, instance_variable, object_name)
342
+ sub_payload = serialize(value, instance_variable)
343
343
 
344
344
  unless value[:serialized_name].to_s.include? '.'
345
345
  payload[value[:serialized_name].to_s] = sub_payload unless sub_payload.nil?
@@ -380,7 +380,7 @@ module MsRest
380
380
  if !element.nil? && element.respond_to?(:validate)
381
381
  element.validate
382
382
  end
383
- payload.push(serialize(mapper[:type][:element], element, object_name))
383
+ payload.push(serialize(mapper[:type][:element], element))
384
384
  end
385
385
  payload
386
386
  end
@@ -391,13 +391,19 @@ module MsRest
391
391
  # @param model_name [String] Name of the model to retrieve.
392
392
  #
393
393
  def get_model(model_name)
394
- consts = @context.class.to_s.split('::')
395
- if consts.any?{ |const| const == 'Models' }
396
- # context is a model class
397
- @context.class
398
- else
399
- # context is a service, so find the model class
400
- Object.const_get(consts[0...-1].join('::') + "::Models::#{model_name}")
394
+ begin
395
+ consts = @context.class.to_s.split('::')
396
+ end_index = 0
397
+ if consts.any?{ |const| const == 'Models' }
398
+ # context is a model class
399
+ end_index = -2
400
+ else
401
+ # context is a service, so find the model class
402
+ end_index = -1
403
+ end
404
+ Object.const_get(consts[0...end_index].join('::') + "::Models::#{model_name}")
405
+ rescue
406
+ Object.const_get("MsRestAzure::#{model_name}")
401
407
  end
402
408
  end
403
409
 
@@ -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.6.4'
6
+ VERSION = '0.7.0'
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.6.4
4
+ version: 0.7.0
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-04-04 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler