diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG index f9aaf225a60bec6b6f162b973cc3f1d3b561e042..7c07ed5368097c9abf5c7ca11ff948a9c57ca71f 100644 --- a/actionwebservice/CHANGELOG +++ b/actionwebservice/CHANGELOG @@ -4,8 +4,7 @@ * Add scaffolding via ActionController::Base.web_service_scaffold for quick testing using a web browser -* ActionWebService::API::Base#api_methods now returns a hash containing ActionWebService::API::Method objects - instead of hashes +* ActionWebService::API::Base#api_methods now returns a hash containing ActionWebService::API::Method objects instead of hashes. However, ActionWebService::API::Method defines a #[]() backwards compatibility method so any existing code utilizing this will still work. * The :layered dispatching mode can now be used with SOAP as well, allowing you to support SOAP and XML-RPC clients for APIs like the metaWeblog API diff --git a/actionwebservice/lib/action_web_service/api.rb b/actionwebservice/lib/action_web_service/api.rb index 87ac1b164eb3e448cb677db59a22b2abbaaaa0f6..d4a42f99ef8bca794478e46dc93c0a8b75a5a3de 100644 --- a/actionwebservice/lib/action_web_service/api.rb +++ b/actionwebservice/lib/action_web_service/api.rb @@ -204,6 +204,16 @@ def expects_to_hash(params) h end + # Backwards compatibility with previous API + def [](sig_type) + case sig_type + when :expects + @expects.map{|x| compat_signature_entry(x)} + when :returns + @returns.map{|x| compat_signature_entry(x)} + end + end + # String representation of this method def to_s fqn = "" @@ -215,6 +225,18 @@ def to_s end private + def compat_signature_entry(entry) + if entry.array? + [compat_signature_entry(entry.element_type)] + else + if entry.spec.is_a?(Hash) + {entry.spec.keys.first => entry.type_class} + else + entry.type_class + end + end + end + def friendly_param(type, show_name=true) name = type.name.to_s type_type = type.array?? type.element_type.type.to_s : type.type.to_s diff --git a/actionwebservice/lib/action_web_service/support/signature_types.rb b/actionwebservice/lib/action_web_service/support/signature_types.rb index 65f63d16e1fe9c5d717fc747fb073c86c6920541..4ab4a08d9b28327e5ec215844c683ded9524c3a7 100644 --- a/actionwebservice/lib/action_web_service/support/signature_types.rb +++ b/actionwebservice/lib/action_web_service/support/signature_types.rb @@ -10,19 +10,20 @@ def canonical_signature(signature) end def canonical_signature_entry(spec, i) + orig_spec = spec name = "param#{i}" if spec.is_a?(Hash) name, spec = spec.keys.first, spec.values.first end type = spec if spec.is_a?(Array) - ArrayType.new(canonical_signature_entry(spec[0], 0), name) + ArrayType.new(orig_spec, canonical_signature_entry(spec[0], 0), name) else type = canonical_type(type) if type.is_a?(Symbol) - BaseType.new(type, name) + BaseType.new(orig_spec, type, name) else - StructuredType.new(type, name) + StructuredType.new(orig_spec, type, name) end end end @@ -126,11 +127,13 @@ def derived_from?(ancestor, child) class BaseType # :nodoc: include SignatureTypes + attr :spec attr :type attr :type_class attr :name - def initialize(type, name) + def initialize(spec, type, name) + @spec = spec @type = canonical_type(type) @type_class = canonical_type_class(@type) @name = name @@ -152,8 +155,8 @@ def structured? class ArrayType < BaseType # :nodoc: attr :element_type - def initialize(element_type, name) - super(Array, name) + def initialize(spec, element_type, name) + super(spec, Array, name) @element_type = element_type end diff --git a/actionwebservice/test/api_test.rb b/actionwebservice/test/api_test.rb index 2278a8213e66e4acc78824d3965c5315d89553f2..83d7196273d95024884301d5eb2e1ac8bc334c47 100644 --- a/actionwebservice/test/api_test.rb +++ b/actionwebservice/test/api_test.rb @@ -91,6 +91,11 @@ def test_parameter_hash assert_equal({:appkey => 5, :publish => false}, hash) end + def test_api_methods_compat + sig = API.api_methods[:named_signature][:expects] + assert_equal [{:appkey=>Integer}, {:publish=>TrueClass}], sig + end + def test_to_s assert_equal 'void Expects(int param0, bool param1)', APITest::API.api_methods[:expects].to_s end