rack-amf 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  spec = Gem::Specification.new do |s|
25
25
  s.name = 'rack-amf'
26
- s.version = '0.0.1'
26
+ s.version = '0.0.2'
27
27
  s.summary = 'AMF serializer/deserializer and AMF gateway packaged as a rack middleware'
28
28
 
29
29
  s.files = FileList['README.rdoc', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.rb']
@@ -194,7 +194,8 @@ module AMF
194
194
 
195
195
  # Fallback serializer
196
196
  props = {}
197
- ruby_obj.public_methods(false).each do |method_name|
197
+ @ignored_props ||= Object.new.public_methods
198
+ (ruby_obj.public_methods - @ignored_props).each do |method_name|
198
199
  # Add them to the prop hash if they take no arguments
199
200
  method_def = ruby_obj.method(method_name)
200
201
  props[method_name] = ruby_obj.send(method_name) if method_def.arity == 0
@@ -34,12 +34,12 @@ module AMF
34
34
  AMF3_XML_MARKER = 0x0B #"\v"
35
35
  AMF3_BYTE_ARRAY_MARKER = 0x0C #"\f"
36
36
 
37
- # Other Markers, some reused
38
- EMPTY_STRING = AMF3_NULL_MARKER
39
- ANONYMOUS_OBJECT = AMF3_NULL_MARKER
40
- DYNAMIC_OBJECT = AMF3_XML_MARKER
41
- CLOSE_DYNAMIC_OBJECT = AMF3_NULL_MARKER
42
- CLOSE_DYNAMIC_ARRAY = AMF3_NULL_MARKER
37
+ # Other Markers
38
+ EMPTY_STRING = 0x01
39
+ ANONYMOUS_OBJECT = 0x01
40
+ DYNAMIC_OBJECT = 0x0B
41
+ CLOSE_DYNAMIC_OBJECT = 0x01
42
+ CLOSE_DYNAMIC_ARRAY = 0x01
43
43
 
44
44
  MAX_INTEGER = 268435455
45
45
  MIN_INTEGER = -268435456
@@ -136,14 +136,11 @@ module AMF
136
136
  # Cache object
137
137
  @object_cache.add_obj obj
138
138
 
139
- class_name = ClassMapper.get_as_class_name obj
140
-
141
- # Any object that has a class name isn't dynamic
142
- unless class_name
143
- stream << DYNAMIC_OBJECT
144
- end
139
+ # Always serialize things as dynamic objects
140
+ stream << DYNAMIC_OBJECT
145
141
 
146
142
  # Write class name/anonymous
143
+ class_name = ClassMapper.get_as_class_name obj
147
144
  if class_name
148
145
  write_utf8_vr class_name, stream
149
146
  else
@@ -11,11 +11,11 @@ module AMF
11
11
  attr_accessor :headers
12
12
  attr_accessor :body
13
13
 
14
+ protected
14
15
  def rand_uuid
15
16
  [8,4,4,4,12].map {|n| rand_hex_3(n)}.join('-').to_s
16
17
  end
17
18
 
18
- private
19
19
  def rand_hex_3(l)
20
20
  "%0#{l}x" % rand(1 << l*4)
21
21
  end
@@ -92,6 +92,17 @@ describe AMF::ClassMapping do
92
92
  hash.should == {'prop_a' => 'Test A', 'prop_b' => 'Test B', 'prop_c' => nil}
93
93
  end
94
94
 
95
+ it "should extract inherited object properties" do
96
+ class RubyClass2 < RubyClass
97
+ end
98
+ obj = RubyClass2.new
99
+ obj.prop_a = 'Test A'
100
+ obj.prop_b = 'Test B'
101
+
102
+ hash = @mapper.props_for_serialization obj
103
+ hash.should == {'prop_a' => 'Test A', 'prop_b' => 'Test B', 'prop_c' => nil}
104
+ end
105
+
95
106
  it "should allow custom serializers" do
96
107
  class CustomSerializer
97
108
  def can_handle? obj
@@ -34,4 +34,16 @@ describe "when handling responses" do
34
34
  expected = request_fixture('simple-response.bin')
35
35
  resp.serialize.should == expected
36
36
  end
37
+
38
+ it "should serialize a AcknowledgeMessage response" do
39
+ ak = AMF::Values::AcknowledgeMessage.new
40
+ ak.clientId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
41
+ ak.messageId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
42
+ ak.timestamp = 0
43
+ resp = AMF::Response.new
44
+ resp.messages << AMF::Message.new('/1/onResult', '', ak)
45
+
46
+ expected = request_fixture('acknowledge-response.bin')
47
+ resp.serialize.should == expected
48
+ end
37
49
  end
@@ -6,7 +6,7 @@ describe AMF::Values::AbstractMessage do
6
6
  end
7
7
 
8
8
  it "should generate conforming uuids" do
9
- @message.rand_uuid.should =~ /[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}/i
9
+ @message.send(:rand_uuid).should =~ /[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}/i
10
10
  end
11
11
  end
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-amf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Hillerson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-03 00:00:00 -04:00
13
+ date: 2009-10-04 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16