From 4dc497b594dff792fd03c5d097f353b13a534197 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Thu, 19 Dec 2013 10:06:38 +0200 Subject: [PATCH 1/2] relax WashOut dependency --- app/helpers/washout_builder_helper.rb | 30 ++++++------- lib/washout_builder.rb | 42 +++++++++++++++++-- lib/washout_builder/document/generator.rb | 4 +- lib/washout_builder/soap.rb | 34 ++++++++++++++- lib/washout_builder/version.rb | 2 +- spec/lib/washout_builder/dispatcher_spec.rb | 2 +- .../document/generator_spec.rb | 6 +-- spec/lib/washout_builder_spec.rb | 3 +- washout_builder.gemspec | 2 +- 9 files changed, 95 insertions(+), 30 deletions(-) diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index cc8e5f7..c8fd4f3 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -90,19 +90,19 @@ def create_html_public_methods(xml, map) def create_html_public_method(xml, operation, formats) - # raise YAML::dump(formats[:in]) + # raise YAML::dump(formats[:builder_in]) xml.h3 "#{operation}" xml.a("name" => "#{operation}") {} xml.p("class" => "pre"){ |pre| - unless formats[:out].nil? - complex_class = formats[:out][0].get_complex_class_name - if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:out][0].type) - xml.span("class" => "blue") { |y| y<< "#{formats[:out][0].type}" } + unless formats[:builder_out].nil? + complex_class = formats[:builder_out][0].get_complex_class_name + if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) + xml.span("class" => "blue") { |y| y<< "#{formats[:builder_out][0].type}" } else unless complex_class.nil? - if formats[:out][0].multiplied == false + if formats[:builder_out][0].multiplied == false pre << "#{complex_class}" else pre << "Array of #{complex_class}" @@ -114,13 +114,13 @@ def create_html_public_method(xml, operation, formats) end xml.span("class" => "bold") {|y| y << "#{operation} (" } - mlen = formats[:in].size + mlen = formats[:builder_in].size xml.br if mlen > 1 spacer = "    " if mlen > 0 j=0 while j 1 ? true : false if WashoutBuilder::Type::BASIC_TYPES.include?(param.type) @@ -156,9 +156,9 @@ def create_html_public_method(xml, operation, formats) xml.ul { j=0 - mlen = formats[:in].size + mlen = formats[:builder_in].size while j "pre") { |pre| if WashoutBuilder::Type::BASIC_TYPES.include?(param.type) @@ -181,13 +181,13 @@ def create_html_public_method(xml, operation, formats) xml.p "Return value:" xml.ul { xml.li { - unless formats[:out].nil? - complex_class = formats[:out][0].get_complex_class_name - if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:out][0].type) - xml.span("class" => "pre") { |xml| xml.span("class" => "blue") { |sp| sp << "#{formats[:out][0].type}" } } + unless formats[:builder_out].nil? + complex_class = formats[:builder_out][0].get_complex_class_name + if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) + xml.span("class" => "pre") { |xml| xml.span("class" => "blue") { |sp| sp << "#{formats[:builder_out][0].type}" } } else unless complex_class.nil? - if formats[:out][0].multiplied == false + if formats[:builder_out][0].multiplied == false xml.span("class" => "pre") { xml.a("href" => "##{complex_class}") { |xml| xml.span("class" => "lightBlue") { |y| y<<"#{complex_class}" } } } else xml.span("class" => "pre") { xml.a("href" => "##{complex_class}") { |xml| xml.span("class" => "lightBlue") { |y| y<<"Array of #{complex_class}" } } } diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index 0f5b1a4..ce3cf08 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -43,16 +43,50 @@ def initialize(attributes = nil) [WashOut::SOAPError, SOAPError].each do |exception_class| exception_class.class_eval do extend WashoutBuilder::Document::VirtusModel - include Virtus.model - attribute :code, Integer - attribute :message, String - attribute :backtrace, String + include Virtus.model + attribute :code, Integer + attribute :message, String + attribute :backtrace, String end end +if defined?(WashOut::SOAP) + WashOut::SOAP::ClassMethods.class_eval do + alias_method :original_soap_action, :soap_action + end +end + + +if defined?(WashOut::Rails::Controller) + WashOut::Rails::Controller::ClassMethods.class_eval do + alias_method :original_soap_action, :soap_action + end +end + +WashOut::Param.class_eval do + + def self.parse_builder_def(soap_config, definition) + raise RuntimeError, "[] should not be used in your params. Use nil if you want to mark empty set." if definition == [] + return [] if definition == nil + + definition = { :value => definition } unless definition.is_a?(Hash) + + definition.collect do |name, opt| + if opt.is_a? WashOut::Param + opt + elsif opt.is_a? Array + WashOut::Param.new(soap_config, name, opt[0], true) + else + WashOut::Param.new(soap_config, name, opt) + end + end + end + +end + ActionController::Base.class_eval do # Define a SOAP service. The function has no required +options+: diff --git a/lib/washout_builder/document/generator.rb b/lib/washout_builder/document/generator.rb index 91f981e..dad2b86 100644 --- a/lib/washout_builder/document/generator.rb +++ b/lib/washout_builder/document/generator.rb @@ -39,7 +39,7 @@ def input_types types = [] unless soap_actions.blank? soap_actions.each do |operation, formats| - (formats[:in]).each do |p| + (formats[:builder_in]).each do |p| types << p end end @@ -51,7 +51,7 @@ def output_types types = [] unless soap_actions.blank? soap_actions.each do |operation, formats| - (formats[:out]).each do |p| + (formats[:builder_out]).each do |p| types << p end end diff --git a/lib/washout_builder/soap.rb b/lib/washout_builder/soap.rb index 13e4955..1c3b8f6 100644 --- a/lib/washout_builder/soap.rb +++ b/lib/washout_builder/soap.rb @@ -3,13 +3,43 @@ module WashoutBuilder module SOAP extend ActiveSupport::Concern - include WashOut::Rails::Controller + include WashOut::SOAP if defined?(WashOut::SOAP) + include WashOut::Rails::Controller if defined?(WashOut::Rails::Controller) - + module ClassMethods + attr_accessor :soap_actions + # Define a SOAP action +action+. The function has two required +options+: + # :args and :return. Each is a type +definition+ of format described in + # WashOut::Param#parse_def. + # + # An optional option :to can be passed to allow for names of SOAP actions + # which are not valid Ruby function names. + def soap_action(action, options={}) + original_soap_action(action, options) + + if action.is_a?(Symbol) + if soap_config.camelize_wsdl.to_s == 'lower' + action = action.to_s.camelize(:lower) + elsif soap_config.camelize_wsdl + action = action.to_s.camelize + end + end + + + current_action = self.soap_actions[action] + current_action[:builder_in] = WashOut::Param.parse_builder_def(soap_config, options[:args]) + current_action[:builder_out] = WashOut::Param.parse_builder_def(soap_config, options[:return]) + + end + end + included do + include WashOut::Configurable if defined?(WashOut::Configurable) + include WashOut::Dispatcher if defined?(WashOut::Dispatcher) include WashoutBuilder::Dispatcher + self.soap_actions = {} end end end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 0c77931..76354ae 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.10.4" + VERSION = "0.11.0" end diff --git a/spec/lib/washout_builder/dispatcher_spec.rb b/spec/lib/washout_builder/dispatcher_spec.rb index d8d2f4c..33400a8 100644 --- a/spec/lib/washout_builder/dispatcher_spec.rb +++ b/spec/lib/washout_builder/dispatcher_spec.rb @@ -24,7 +24,7 @@ def dispatcher_method :config => ApiController.soap_config, :service_class => ApiController, :soap_actions => {'dispatcher_method' => - {:args => nil, :return => nil, :in => [], :out => [], :to => 'dispatcher_method'} + {:args => nil, :return => nil, :in => [], :out => [],:builder_in => [], :builder_out => [], :to => 'dispatcher_method'} } ) get :_generate_doc diff --git a/spec/lib/washout_builder/document/generator_spec.rb b/spec/lib/washout_builder/document/generator_spec.rb index 44f45cf..d7b2f16 100644 --- a/spec/lib/washout_builder/document/generator_spec.rb +++ b/spec/lib/washout_builder/document/generator_spec.rb @@ -12,7 +12,7 @@ let(:soap_actions) { {'dispatcher_method' => - {:args => nil, :return => nil, :in => [], :out => [], :to => 'dispatcher_method'} + {:args => nil, :return => nil, :in => [], :out => [], :builder_in => [], :builder_out => [], :to => 'dispatcher_method'} } } let(:service_class) { ApiController } @@ -68,7 +68,7 @@ context "input types" do let(:expected) { types = [] soap_actions.each do |operation, formats| - (formats[:in]).each do |p| + (formats[:builder_in]).each do |p| types << p end end @@ -81,7 +81,7 @@ context "output types" do let(:expected) { types = [] soap_actions.each do |operation, formats| - (formats[:out]).each do |p| + (formats[:builder_out]).each do |p| types << p end end diff --git a/spec/lib/washout_builder_spec.rb b/spec/lib/washout_builder_spec.rb index 85e95fd..4358e7a 100644 --- a/spec/lib/washout_builder_spec.rb +++ b/spec/lib/washout_builder_spec.rb @@ -7,7 +7,8 @@ before(:each) do WashOut::Rails::Engine.config.wash_out[:wsdl_style] = 'rpc' WashOut::Rails::Engine.config.wash_out[:parser] = :nokogiri - WashOut::Rails::Engine.config.wash_out[:catch_xml_errors] = true + WashOut::Rails::Engine.config.wash_out[:catch_xml_errors] = true + WashOut::Rails::Engine.config.wash_out[:camelize_wsdl] = "lower" end let :nori do diff --git a/washout_builder.gemspec b/washout_builder.gemspec index 5943862..01bd348 100644 --- a/washout_builder.gemspec +++ b/washout_builder.gemspec @@ -15,6 +15,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = s.files.grep(/^(spec)/) s.require_paths = ["lib"] - s.add_dependency("wash_out", ">= 0.10.0.beta.1") + s.add_dependency("wash_out", ">= 0.9.0") s.add_dependency("virtus", ">= 1.0.0") end From af7bfbafdadec6d71fc5d89e5a3232fc757803e1 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Thu, 19 Dec 2013 10:07:06 +0200 Subject: [PATCH 2/2] relax WashOut dependency --- lib/washout_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index ce3cf08..49af1c8 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -83,7 +83,7 @@ def self.parse_builder_def(soap_config, definition) WashOut::Param.new(soap_config, name, opt) end end - end + end end