p.summary = "Ruby libraries for Thrift (a language-agnostic RPC system)"
p.url = "http://incubator.apache.org/thrift/"
p.include_rakefile = true
- p.version = "0.2.1"
+ p.version = "0.2.2"
p.rubygems_version = ">= 1.2.0"
end
name = field_info[:name]
value = instance_variable_get("@#{name}")
unless skip_optional_nulls && field_info[:optional] && value.nil?
- fields << "#{name}:#{value.inspect}"
+ fields << "#{name}:#{inspect_field(value, field_info)}"
end
end
"<#{self.class} #{fields.join(", ")}>"
:value => field[:value],
:element => field[:element] }
end
+
+ def inspect_field(value, field_info)
+ if enum_class = field_info[:enum_class]
+ "#{enum_class.const_get(:VALUE_MAP)[value]} (#{value})"
+ elsif value.is_a? Hash
+ if field_info[:type] == Types::MAP
+ map_buf = []
+ value.each do |k, v|
+ map_buf << inspect_field(k, field_info[:key]) + ": " + inspect_field(v, field_info[:value])
+ end
+ "{" + map_buf.join(", ") + "}"
+ else
+ # old-style set
+ inspect_collection(value.keys, field_info)
+ end
+ elsif value.is_a? Array
+ inspect_collection(value, field_info)
+ elsif value.is_a? Set
+ inspect_collection(value, field_info)
+ else
+ value.inspect
+ end
+ end
+
+ def inspect_collection(collection, field_info)
+ buf = []
+ collection.each do |k|
+ buf << inspect_field(k, field_info[:element])
+ end
+ "[" + buf.join(", ") + "]"
+ end
+
end
end
\ No newline at end of file
end
def inspect
- "<#{self.class} #{@setfield}: #{@value}>"
+ "<#{self.class} #{@setfield}: #{inspect_field(@value, struct_fields[name_to_id(@setfield.to_s)])}>"
end
def read(iprot)
1: string greeting = "hello world"
}
-union My_union {
- 1: bool im_true,
- 2: byte a_bite,
- 3: i16 integer16,
- 4: i32 integer32,
- 5: i64 integer64,
- 6: double double_precision,
- 7: string some_characters,
- 8: i32 other_i32
-}
-
-struct Struct_with_union {
- 1: My_union fun_union
- 2: i32 integer32
- 3: string some_characters
-}
-
enum SomeEnum {
ONE
TWO
}
+struct StructWithSomeEnum {
+ 1: SomeEnum some_enum;
+}
+
union TestUnion {
/**
* A doc string
oneway void shutdown()
void sleep(1:double seconds)
}
+
+union My_union {
+ 1: bool im_true,
+ 2: byte a_bite,
+ 3: i16 integer16,
+ 4: i32 integer32,
+ 5: i64 integer64,
+ 6: double double_precision,
+ 7: string some_characters,
+ 8: i32 other_i32
+ 9: SomeEnum some_enum;
+ 10: map<SomeEnum, list<SomeEnum>> my_map;
+}
+
+struct Struct_with_union {
+ 1: My_union fun_union
+ 2: i32 integer32
+ 3: string some_characters
+}
+
+struct StructWithEnumMap {
+ 1: map<SomeEnum, list<SomeEnum>> my_map;
+}
\ No newline at end of file
Foo.new(:simple => 52).should_not == Foo.new
end
+ it "should print enum value names in inspect" do
+ StructWithSomeEnum.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>"
+
+ StructWithEnumMap.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>"
+ end
+
it "should read itself off the wire" do
struct = Foo.new
prot = BaseProtocol.new(mock("transport"))
union.get_set_field.should == :integer32
union.get_value.should == 26
end
+
+ it "should print enum value name when inspected" do
+ My_union.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
+
+ My_union.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
+ end
end
end