Author: bryanduxbury
Date: Wed Feb 17 22:27:27 2010
New Revision: 911199
URL: http://svn.apache.org/viewvc?rev=911199&view=rev
Log:
THRIFT-707. Support old-style constructors for Union structs
Modified:
incubator/thrift/trunk/lib/rb/lib/thrift/union.rb
incubator/thrift/trunk/lib/rb/spec/union_spec.rb
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/union.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/union.rb?rev=911199&r1=911198&r2=911199&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/union.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/union.rb Wed Feb 17 22:27:27 2010
@@ -21,6 +21,14 @@
class Union
def initialize(name=nil, value=nil)
if name
+ if name.is_a? Hash
+ if name.size > 1
+ raise "#{self.class} cannot be instantiated with more than one
field!"
+ end
+
+ name, value = name.keys.first, name.values.first
+ end
+
if value.nil?
raise Exception, "Union #{self.class} cannot be instantiated with
setfield and nil value!"
end
Modified: incubator/thrift/trunk/lib/rb/spec/union_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/union_spec.rb?rev=911199&r1=911198&r2=911199&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/union_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/union_spec.rb Wed Feb 17 22:27:27 2010
@@ -141,5 +141,11 @@
swu2.read(proto)
swu2.should == swu
end
+
+ it "should support old style constructor" do
+ union = My_union.new(:integer32 => 26)
+ union.get_set_field.should == :integer32
+ union.get_value.should == 26
+ end
end
end