public this repo is viewable by everyone
Description: Ruby WDDX gem.
Homepage: http://code.juretta.com/ruby/wddx/
Clone URL: git://github.com/juretta/wddx.git
Merge branch 'master' of git@github.com:juretta/wddx
juretta (author)
15 days ago
commit  3d5df54c4cc87211b70f321a16271c28aff2e634
tree    a1a7d48da1700c43999773930572d9930cf66ba7
parent  8003c797e107a041ed79afb8e4f048241d2241a6 parent  d4aab5d09f48e6950d7104bb432d76a0a9a3e80f
...
 
 
 
 
1
2
3
...
34
35
36
37
38
 
...
1
2
3
4
5
6
7
...
38
39
40
 
41
42
0
@@ -1,3 +1,7 @@
0
+=== 0.4.0 / 2008-04-31
0
+* Minor code cleanup.
0
+* WDDX library now works in Ruby 1.8 and 1.9
0
+
0
 === 0.4.0 / 2008-03-04
0
 * Added wddx binary. Pretty prints a wddx data structure.
0
 
0
@@ -34,4 +38,4 @@ Added Rails support
0
 Rails ActiveRecord::Base objects can be serialised to WDDX-XML using the +to_wddx+ method.
0
 
0
 === 0.1.0 / 2006-12-18
0
-Initial release
0
\ No newline at end of file
0
+Initial release
...
39
40
41
42
 
43
44
45
...
96
97
98
99
 
100
101
102
...
128
129
130
131
132
133
134
...
139
140
141
142
 
143
144
145
...
151
152
153
154
 
155
156
157
...
166
167
168
169
170
 
...
39
40
41
 
42
43
44
45
...
96
97
98
 
99
100
101
102
...
128
129
130
 
131
132
133
...
138
139
140
 
141
142
143
144
...
150
151
152
 
153
154
155
156
...
165
166
167
 
168
169
0
@@ -39,7 +39,7 @@ module WDDX
0
       if obj.respond_to?(:read)
0
         return deserialize(obj.read)
0
       end
0
- return deserialize(obj)
0
+ deserialize(obj)
0
     end
0
     alias :load :open
0
     
0
@@ -96,7 +96,7 @@ module WDDX
0
         end
0
       end
0
     else
0
- self.instance_variables.collect {|var| hash[var.gsub(/@/, "")] = instance_variable_get(var)}
0
+ hash = self.instance_variables.sort.inject({}) {|h, var| h[var.to_s.gsub(/@/, "")] = instance_variable_get(var); h}
0
     end
0
     hash.wddx_serialize
0
   end
0
@@ -128,7 +128,6 @@ module WDDX
0
   # object after decoding. It can also be used for efficient allocation of
0
   # memory during the decoding process.
0
   class Binary < WddxData
0
- require "base64"
0
     attr_accessor :bin_data
0
     
0
     # Initialize with the raw binary data (to be encoded with Base64)
0
@@ -139,7 +138,7 @@ module WDDX
0
 
0
     # set binary data
0
     def encoded_data=(arg)
0
- @bin_data = Base64.decode64(arg)
0
+ @bin_data = arg.unpack( 'm' )[0]
0
     end
0
     
0
     # length of the raw binary data in bytes
0
@@ -151,7 +150,7 @@ module WDDX
0
     # Returns an Base64 encoded string
0
     def encode
0
       return @_data unless @_data.nil?
0
- @_data = Base64.encode64(@bin_data).chomp unless @bin_data.nil?
0
+ @_data = [@bin_data].pack( 'm' ).chomp if @bin_data
0
       @_data
0
     end
0
     
0
@@ -166,4 +165,4 @@ module WDDX
0
 end
0
 
0
 # Add "to_wddx"
0
-[WDDX::Struct, WDDX::Binary, WDDX::RecordSet].each {|clazz| clazz.class_eval { include WDDX::Core } }
0
\ No newline at end of file
0
+[WDDX::Struct, WDDX::Binary, WDDX::RecordSet].each {|clazz| clazz.class_eval { include WDDX::Core } }
...
43
44
45
46
47
48
49
...
84
85
86
87
88
89
 
90
91
92
...
94
95
96
97
 
98
99
100
...
131
132
133
134
135
 
...
43
44
45
 
46
47
48
...
83
84
85
 
 
 
86
87
88
89
...
91
92
93
 
94
95
96
97
...
128
129
130
 
131
132
0
@@ -43,7 +43,6 @@ module WDDX
0
       end
0
 
0
       def tag_end(name)
0
- #puts "Name: #{name}"
0
         case name.downcase
0
           when "comment"
0
             @wddx_packet.comment = @text.strip
0
@@ -84,9 +83,7 @@ module WDDX
0
            when "array", "field"
0
              @children.collect {|c| c.to_ruby }
0
            when "struct"
0
- h = {}
0
- @children.each {|c| var = c.to_ruby; h[var.key] = var.value}
0
- h
0
+ @children.inject({}) {|mem, c| var = c.to_ruby; mem[var.key] = var.value; mem}
0
            when "var"
0
              WDDX::Var.new(@attributes["name"], @children.first.to_ruby)
0
            when "null"
0
@@ -94,7 +91,7 @@ module WDDX
0
            when "number"
0
              (@text =~ /\./ ) ? @text.to_f : @text.to_i
0
            when "boolean"
0
- (@attributes["value"].eql?("true")) ? true : false
0
+ @attributes["value"].eql?("true")
0
            # Date-time values-
0
            # Date-time values are encoded according to the full form of ISO8601,
0
            # e.g., 1998-9-15T09:05:32+4:0. Note that single-digit values for months,
0
@@ -131,4 +128,4 @@ if __FILE__ == $0
0
 end
0
 
0
 __END__
0
-<?xml version="1.0"?><wddxPacket version='1.0'><header/><data><string>A</string></data></wddxPacket>
0
\ No newline at end of file
0
+<?xml version="1.0"?><wddxPacket version='1.0'><header/><data><string>A</string></data></wddxPacket>
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@ module Wddx #:nodoc:
0
   module VERSION #:nodoc:
0
     MAJOR = 0
0
     MINOR = 4
0
- TINY = 0
0
+ TINY = 1
0
 
0
     STRING = [MAJOR, MINOR, TINY].join('.')
0
   end
...
73
74
75
76
77
 
78
79
 
 
 
 
 
 
 
 
 
80
81
82
...
73
74
75
 
 
76
77
 
78
79
80
81
82
83
84
85
86
87
88
89
0
@@ -73,10 +73,17 @@ class TcWddxDeserializerTest < Test::Unit::TestCase
0
   def test_a_binary
0
      binary = @wddx.data["aBinary"]
0
      assert binary.kind_of?(WDDX::Binary)
0
- #assert_equal "MIIBJASHETAS", binary.encode
0
- # Todo: implement
0
+ assert_equal "MIIBJASHETAS", binary.encode
0
   end
0
-
0
+
0
+ # File handling is different in Ruby 1.9 - use "rb:ascii-8bit" for 1.9
0
+ def test_binary
0
+ mode = is19? ? "rb:ascii-8bit" : "rb"
0
+ bin_file_content = File.open("#{FIXTURES}/favicon.ico", mode).read
0
+ c = WDDX.load(WDDX::Binary.new(bin_file_content).to_wddx)
0
+ assert_equal bin_file_content, c.data.bin_data
0
+ end
0
+
0
   def no_test_ascii_characters
0
     # <wddxPacket version='1.0'><header/><data><string>A</string></data></wddxPacket>
0
     # int(65)
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ class CustomClass
0
   end
0
   
0
   def to_wddx_properties
0
- [:to_s, "@name"]
0
+ ["@name", :to_s]
0
   end
0
 end
0
 
...
3
4
5
 
 
 
 
6
7
8
9
 
...
3
4
5
6
7
8
9
10
11
 
12
13
0
@@ -3,6 +3,10 @@ require 'test/unit'
0
 require File.dirname(__FILE__) + '/../lib/wddx'
0
 FIXTURES = File.dirname(__FILE__) + "/fixtures"
0
 
0
+def is19?
0
+ RUBY_VERSION >= "1.9.0"
0
+end
0
+
0
 def read_fixture(f)
0
   File.read(File.join(FIXTURES, f)).gsub(/\t|\n/, "").gsub(/^(.*)<wddx/, "<wddx").gsub(/"/, "'")
0
-end
0
\ No newline at end of file
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
0
@@ -0,0 +1,27 @@
0
+
0
+
0
+class A
0
+ def initialize
0
+ @name = "Stefan"
0
+ @last = "Saasen"
0
+ @num = 10
0
+ @z = :r
0
+ @ary = [1,2]
0
+ end
0
+end
0
+
0
+class B
0
+ def initialize
0
+ @z = :r
0
+ @last = "Saasen"
0
+ @ary = [1,2]
0
+ @name = "Stefan"
0
+ @num = 5
0
+ end
0
+end
0
+
0
+puts "Ruby Version #{RUBY_VERSION}"
0
+
0
+p A.new.instance_variables.sort
0
+p B.new.instance_variables.sort
0
+

Comments

    No one has commented yet.