Skip to content

Commit

Permalink
Update to Fixnum/Bignum
Browse files Browse the repository at this point in the history
  • Loading branch information
razum2um committed Jun 1, 2018
1 parent 9e70479 commit 593e84e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/soap/mapping/encodedregistry.rb
Expand Up @@ -6,6 +6,11 @@
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.

# in 2.4, 2.5 Fixnum/Bignum aliased to 'Integer'
FixnumShim = 1.class
FIXNUM_PRESENT = FixnumShim.name == 'Fixnum'
BignumShim = (10**20).class
BIGNUM_PRESENT = BignumShim.name == 'Bignum'

require 'soap/baseData'
require 'soap/mapping/mapping'
Expand Down Expand Up @@ -122,7 +127,7 @@ def find_mapped_obj_class(target_soap_class)

StringFactory = StringFactory_.new
BasetypeFactory = BasetypeFactory_.new
FixnumFactory = FixnumFactory_.new
FixnumFactory = FixnumFactory_.new if FIXNUM_PRESENT
DateTimeFactory = DateTimeFactory_.new
ArrayFactory = ArrayFactory_.new
Base64Factory = Base64Factory_.new
Expand All @@ -146,7 +151,6 @@ def find_mapped_obj_class(target_soap_class)
{:derived_class => true}],
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
{:derived_class => true}],
[::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
{:derived_class => true}],
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
Expand Down Expand Up @@ -199,6 +203,8 @@ def find_mapped_obj_class(target_soap_class)
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
]

SOAPBaseMap << [FixnumShim, ::SOAP::SOAPInt, FixnumFactory] if FIXNUM_PRESENT

RubyOriginalMap = [
[::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
[::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
Expand All @@ -212,7 +218,6 @@ def find_mapped_obj_class(target_soap_class)
{:derived_class => true}],
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
{:derived_class => true}],
[::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
{:derived_class => true}],
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
Expand Down Expand Up @@ -263,6 +268,8 @@ def find_mapped_obj_class(target_soap_class)
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
]

RubyOriginalMap << [FixnumShim, ::SOAP::SOAPInt, FixnumFactory] if FIXNUM_PRESENT

attr_accessor :default_factory
attr_accessor :excn_handler_obj2soap
attr_accessor :excn_handler_soap2obj
Expand Down Expand Up @@ -411,7 +418,10 @@ def addextend2obj(obj, attr)
end

def addextend2soap(node, obj)
return if [Symbol, Fixnum, Bignum, Float].any?{ |c| obj.is_a?(c) }
return if [Symbol, Integer, Float].any?{ |c| obj.is_a?(c) }
return if FIXNUM_PRESENT && obj.is_a?(FixnumShim)
return if BIGNUM_PRESENT && obj.is_a?(BignumShim)
return if obj.is_a?(String) && obj.frozen?
list = (class << obj; self; end).ancestors - obj.class.ancestors
list = list.reject{|c| c.class == Class } ## As of Ruby 2.1 Singleton Classes are now included in the ancestry. Need to filter those out here.

Expand Down
6 changes: 5 additions & 1 deletion test/soap/test_styleuse.rb
Expand Up @@ -309,7 +309,11 @@ def test_doc_lit_doc_enc
def test_doc_enc_doc_lit
ret1, ret2 = @client.doc_enc_doc_lit('a', 1)
# literal Array
assert_equal(['String', 'Fixnum'], ret1['obj1']['klass'])
if (RUBY_VERSION.to_f <= 2.3)
assert_equal(['String', 'Fixnum'], ret1['obj1']['klass'])
else
assert_equal(['String', 'Integer'], ret1['obj1']['klass'])
end
# same value
assert_equal(ret1['obj1']['klass'], ret2['obj2']['klass'])
# not the same object (not encoded)
Expand Down

0 comments on commit 593e84e

Please sign in to comment.