ruby-serial 1.0.1.20130709 → 1.0.2.20130725

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  * 1.0.0.20130705
4
4
  * 1.0.1.20130709
5
+ * 1.0.2.20130725
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  = Ruby-Serial Release History
2
2
 
3
+ == 1.0.2.20130725 (Beta)
4
+
5
+ * Can serialize objects with constructors having parameters
6
+ * Added support for Range
7
+
3
8
  == 1.0.1.20130709 (Beta)
4
9
 
5
10
  * Added support for Encoding objects
data/ReleaseInfo CHANGED
@@ -2,7 +2,7 @@
2
2
  # This file has been generated by RubyPackager during a delivery.
3
3
  # More info about RubyPackager: http://rubypackager.sourceforge.net
4
4
  {
5
- :version => '1.0.1.20130709',
5
+ :version => '1.0.2.20130725',
6
6
  :tags => [ 'Beta' ],
7
7
  :dev_status => 'Beta'
8
8
  }
@@ -12,5 +12,6 @@ module RubySerial
12
12
  # No duplicates allowed.
13
13
  CLASS_ID_SYMBOL = "\x00\xEE".force_encoding(Encoding::UTF_8)
14
14
  CLASS_ID_ENCODING = "\x00\xDD".force_encoding(Encoding::UTF_8)
15
+ CLASS_ID_RANGE = "\x00\xCC".force_encoding(Encoding::UTF_8)
15
16
 
16
17
  end
@@ -52,6 +52,9 @@ module RubySerial
52
52
  return decoded_obj[OBJECT_CONTENT_REFERENCE].to_sym
53
53
  elsif (decoded_obj[OBJECT_CLASSNAME_REFERENCE] == CLASS_ID_ENCODING)
54
54
  return Encoding::find(decoded_obj[OBJECT_CONTENT_REFERENCE])
55
+ elsif (decoded_obj[OBJECT_CLASSNAME_REFERENCE] == CLASS_ID_RANGE)
56
+ serialized_first, serialized_last, exclude_end = decoded_obj[OBJECT_CONTENT_REFERENCE]
57
+ return (exclude_end ? (get_original_rec(serialized_first)...get_original_rec(serialized_last)) : (get_original_rec(serialized_first)..get_original_rec(serialized_last)) )
55
58
  elsif (decoded_obj[OBJECT_CLASSNAME_REFERENCE] == nil)
56
59
  # Normal hash
57
60
  hash_obj = ((container_to_fill == nil) ? {} : container_to_fill)
@@ -62,7 +65,7 @@ module RubySerial
62
65
  else
63
66
  # We deserialize a home-made object
64
67
  # Instantiate the needed class
65
- new_obj = ((container_to_fill == nil) ? eval(decoded_obj[OBJECT_CLASSNAME_REFERENCE]).new : container_to_fill)
68
+ new_obj = ((container_to_fill == nil) ? eval(decoded_obj[OBJECT_CLASSNAME_REFERENCE]).allocate : container_to_fill)
66
69
  instance_vars = {}
67
70
  decoded_obj[OBJECT_CONTENT_REFERENCE].each do |var_name, serialized_value|
68
71
  instance_vars[var_name] = get_original_rec(serialized_value)
@@ -75,7 +78,7 @@ module RubySerial
75
78
  obj_id = decoded_obj[OBJECT_ID_REFERENCE]
76
79
  if (@decoded_shared_objs[obj_id] == nil)
77
80
  # Instantiate it already for cyclic decoding (avoids infinite loops)
78
- @decoded_shared_objs[obj_id] = eval(@serialized_shared_objs[obj_id][0]).new
81
+ @decoded_shared_objs[obj_id] = eval(@serialized_shared_objs[obj_id][0]).allocate
79
82
  get_original_rec(@serialized_shared_objs[obj_id][1], @decoded_shared_objs[obj_id])
80
83
  end
81
84
  return @decoded_shared_objs[obj_id]
@@ -93,8 +93,10 @@ module RubySerial
93
93
  (obj == true) or
94
94
  (obj == false))
95
95
  return obj
96
+ #
97
+ # First handle objects that are not shareable
98
+ #
96
99
  elsif (obj.is_a?(Symbol))
97
- # TODO (MessagePack): Remove this if MessagePack handles Symbols one day
98
100
  return {
99
101
  OBJECT_CLASSNAME_REFERENCE => CLASS_ID_SYMBOL,
100
102
  OBJECT_CONTENT_REFERENCE => obj.to_s
@@ -104,12 +106,18 @@ module RubySerial
104
106
  OBJECT_CLASSNAME_REFERENCE => CLASS_ID_ENCODING,
105
107
  OBJECT_CONTENT_REFERENCE => obj.name
106
108
  }
109
+ #
110
+ # Handle shared objects
111
+ #
107
112
  elsif (check_shared and
108
113
  (@shared_objs[obj.object_id] != nil))
109
114
  # This object is shared: store its object_id only
110
115
  return {
111
116
  OBJECT_ID_REFERENCE => obj.object_id
112
117
  }
118
+ #
119
+ # Handle shareable objects
120
+ #
113
121
  elsif (obj.is_a?(Array))
114
122
  # First serialize its items
115
123
  return obj.map { |item| get_msgpack_compatible_rec(item) }
@@ -122,6 +130,11 @@ module RubySerial
122
130
  return hash_to_store
123
131
  elsif (obj.is_a?(String))
124
132
  return obj
133
+ elsif (obj.is_a?(Range))
134
+ return {
135
+ OBJECT_CLASSNAME_REFERENCE => CLASS_ID_RANGE,
136
+ OBJECT_CONTENT_REFERENCE => [ get_msgpack_compatible_rec(obj.first), get_msgpack_compatible_rec(obj.last), obj.exclude_end? ]
137
+ }
125
138
  else
126
139
  # Handle other objects
127
140
  serialized_instance_vars = {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.20130709
4
+ version: 1.0.2.20130725
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-09 00:00:00.000000000 Z
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack