right_support 2.8.25 → 2.8.26

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
  SHA1:
3
- metadata.gz: d4d1fe10f00edff41986d12d3974498f8dc14ace
4
- data.tar.gz: 7358538374cc52741957dd32c5cd86e28322d72a
3
+ metadata.gz: 6010fe3e9ebbaa222eacaf224b0576a36e350f7c
4
+ data.tar.gz: a4a49a381d7a250a19230b0a3cd848436a51f221
5
5
  SHA512:
6
- metadata.gz: d23cdbb1ed41af6ea575de60bedc7de338317c90866fbe52496f80f0bff85fcc4cf32afec52a5bbcb00e0e43ec7c608f556aa7b4c7b827e42d3669514d187230
7
- data.tar.gz: 3cbded75569f2a003032861dffb60414cb050274c85f6cd30fd278f245cd1525cda2b6ea10c8e5c72bb156c0916e0a8c3618cccb78117d02611d644f82b83036
6
+ metadata.gz: a74303a4224cd7bc1ffa4bb3d65df38b4664baa9c55ba31f63327696ff598756c7898d6de68ac625caa8f0e453e5811c73adf8b725a9dc709ebdf200d5f09189
7
+ data.tar.gz: 9f1d6b77e03702c6e8f83e04633f5fe8708d79f4a790dfbae77a4c860b5da1772576405db4d30d00f8eb19cb15b21d9591b3a91b575806702bd212b68f88cd91
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.25
1
+ 2.8.26
@@ -104,5 +104,9 @@ Feature: JSON serialization
104
104
 
105
105
  Scenario: unrecognized Ruby object class
106
106
  When I unserialize the JSON value: {"_ruby_class":"DoesNotExist","hello":"world"}
107
- Then the unserialized object should be an OpenStruct
107
+ Then the unserialized object should be an RightSupport::Data::UnknownType
108
108
  And the unserialized object should have a "hello" attribute with value: "world"
109
+
110
+ Scenario: unrecognized Ruby object class
111
+ When I serialize the Ruby value: RightSupport::Data::UnknownType.new("DoesNotExist", {"hello" => "world"})
112
+ Then the serialized value should be: {"_ruby_class":"DoesNotExist","hello":"world"}
@@ -210,6 +210,12 @@ module RightSupport::Data
210
210
  # Ruby Class/Module needs special handling - no instance vars
211
211
  { @marker => object.class.name,
212
212
  CLASS_ESCAPE_KEY => object.name }
213
+ when UnknownType
214
+ # An unknown Ruby type that got deserialized and needs to be round-tripped.
215
+ object.marshal_dump.inject({@marker => object.__typename__}) do |result, (k,v)|
216
+ result[k.to_s] = object_to_jsonish(v)
217
+ result
218
+ end
213
219
  else
214
220
  # Generic serialized object; convert to Hash.
215
221
  hash = {}
@@ -257,6 +263,7 @@ module RightSupport::Data
257
263
  jsonish = Time.at(hash.delete(TIME_ESCAPE_KEY))
258
264
  else
259
265
  # Generic serialized object
266
+ klassname = klass
260
267
  klass = klass.to_const
261
268
 
262
269
  if klass
@@ -267,9 +274,9 @@ module RightSupport::Data
267
274
  jsonish.instance_variable_set("@#{k}", jsonish_to_object(v))
268
275
  end
269
276
  else
270
-
271
- # Unknown types turn into an OpenStruct.
272
- jsonish = OpenStruct.new(hash.inject({}) do |result, (k, v)|
277
+ # Objects of unknown types are represented by a special derivative of OpenStruct
278
+ # so we can round-trip them later.
279
+ jsonish = UnknownType.new(klassname, hash.inject({}) do |result, (k, v)|
273
280
  result[k] = jsonish_to_object(v)
274
281
  result
275
282
  end)
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'ostruct'
24
+
25
+ module RightSupport::Data
26
+ # A type that can be instantiated by the DataSerializer (or anyone else) when an unknown Ruby
27
+ # type is encountered in serialized data. It functions like an OpenStruct, but it has a distinct
28
+ # type identity so the DataSerializer can work with it.
29
+ #
30
+ # UnknownType remembers the original Ruby type name of the serialized object so it can be
31
+ # dumped back to a serialization stream without losing type identity or attribute information.
32
+ class UnknownType < OpenStruct
33
+ attr_reader :__typename__
34
+
35
+ # Construct a new object representing a serialized object of unknown type.
36
+ # @param [String] typename
37
+ # @param [Hash] attributes
38
+ def initialize(typename, attributes)
39
+ @__typename__ = typename
40
+ super(attributes)
41
+ end
42
+ end
43
+ end
@@ -29,6 +29,7 @@ module RightSupport
29
29
  end
30
30
  end
31
31
 
32
+ require 'right_support/data/unknown_type'
32
33
  require 'right_support/data/serializer'
33
34
  require 'right_support/data/hash_tools'
34
35
  require 'right_support/data/uuid'
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: right_support 2.8.25 ruby lib
5
+ # stub: right_support 2.8.26 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "right_support"
9
- s.version = "2.8.25"
9
+ s.version = "2.8.26"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
14
- s.date = "2014-08-01"
14
+ s.date = "2014-08-06"
15
15
  s.description = "A toolkit of useful, reusable foundation code created by RightScale."
16
16
  s.email = "support@rightscale.com"
17
17
  s.extra_rdoc_files = [
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
54
54
  "lib/right_support/data.rb",
55
55
  "lib/right_support/data/hash_tools.rb",
56
56
  "lib/right_support/data/serializer.rb",
57
+ "lib/right_support/data/unknown_type.rb",
57
58
  "lib/right_support/data/uuid.rb",
58
59
  "lib/right_support/db.rb",
59
60
  "lib/right_support/db/cassandra_model.rb",
@@ -140,7 +141,7 @@ Gem::Specification.new do |s|
140
141
  ]
141
142
  s.homepage = "https://github.com/rightscale/right_support"
142
143
  s.licenses = ["MIT"]
143
- s.rubygems_version = "2.2.0"
144
+ s.rubygems_version = "2.2.2"
144
145
  s.summary = "Reusable foundation code."
145
146
  end
146
147
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.25
4
+ version: 2.8.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Spataro
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-08-01 00:00:00.000000000 Z
16
+ date: 2014-08-06 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: A toolkit of useful, reusable foundation code created by RightScale.
19
19
  email: support@rightscale.com
@@ -58,6 +58,7 @@ files:
58
58
  - lib/right_support/data.rb
59
59
  - lib/right_support/data/hash_tools.rb
60
60
  - lib/right_support/data/serializer.rb
61
+ - lib/right_support/data/unknown_type.rb
61
62
  - lib/right_support/data/uuid.rb
62
63
  - lib/right_support/db.rb
63
64
  - lib/right_support/db/cassandra_model.rb
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  version: '0'
162
163
  requirements: []
163
164
  rubyforge_project:
164
- rubygems_version: 2.2.0
165
+ rubygems_version: 2.2.2
165
166
  signing_key:
166
167
  specification_version: 4
167
168
  summary: Reusable foundation code.