From 8b70d6539cd09d904696fabc240d38439bfd8097 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Thu, 19 Dec 2013 10:55:27 +0200 Subject: [PATCH] relax washOut dependency to 0.9.1 --- README.rdoc | 8 ++++---- app/helpers/washout_builder_helper.rb | 2 +- lib/washout_builder.rb | 14 +++++++++++--- lib/washout_builder/document/generator.rb | 10 +++++----- lib/washout_builder/engine.rb | 5 +++-- lib/washout_builder/type.rb | 9 +++++++++ lib/washout_builder/version.rb | 2 +- washout_builder.gemspec | 2 +- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.rdoc b/README.rdoc index 76c560e..9ea74e3 100644 --- a/README.rdoc +++ b/README.rdoc @@ -90,11 +90,11 @@ Here is an example : :description => "some description about this method to show in the documentation" -The exception classes used must inherit from WashOut::SOAPError, which has by default a error code and a message as attributes but you can extend it by adding more attributes to your own custom class. +The exception classes used must inherit from WashOut::Dispatcher::SOAPError, which has by default a error code and a message as attributes but you can extend it by adding more attributes to your own custom class. The WashOut::SoapError now includes Virtus.model from +virtus+ gem. This way you can add attributes like this: - class MyCustomSoapError < WashOut::SOAPError + class MyCustomSoapError < WashOut::Dispatcher::SOAPError attribute :custom_attribute, String attribute :other_custom_attribute, Integer @@ -103,7 +103,7 @@ The WashOut::SoapError now includes Virtus.model from +virtus+ gem. This way you You can also specify complex types like this: - class MyCustomSoapError < WashOut::SOAPError + class MyCustomSoapError < WashOut::Dispatcher::SOAPError attribute :errors,Array[Integer] attribute :custom, Array[MyCustomModel] @@ -116,7 +116,7 @@ Please checkout {Virtus Gem}[https://github.com/solnic/virtus] for further docum You can also use aggregation with another fault class exception like this: - class MyCustomSoapError < WashOut::SOAPError + class MyCustomSoapError < WashOut::Dispatcher::SOAPError attribute :errors, Array[MyOtherCustomSoapError] diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index c8fd4f3..b613c46 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -204,7 +204,7 @@ def create_html_public_method(xml, operation, formats) faults = formats[:raises] faults = [formats[:raises]] if !faults.is_a?(Array) - faults = faults.select { |x| x.is_a?(Class) && (x.ancestors.include?(WashOut::SOAPError) || x.ancestors.include?(SOAPError) ) } + faults = faults.select { |x| x.is_a?(Class) && (x.ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present? || WashoutBuilder::Type.get_fault_classes.include?(x) ) } unless faults.blank? xml.p "Exceptions:" xml.ul { diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index 49af1c8..4c656fe 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -30,7 +30,7 @@ def wash_out(controller_name, options={}) Virtus::InstanceMethods::Constructor.class_eval do alias_method :original_initialize,:initialize def initialize(attributes = nil) - if self.class.ancestors.include?(WashOut::SOAPError) || self.is_a?(WashOut::SOAPError) || self.class.ancestors.include?(SOAPError) ||self.is_a?(SOAPError) + if self.class.ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present? or WashoutBuilder::Type.get_fault_classes.include?(self.class) attributes = {:message => attributes} unless attributes.is_a?(Hash) end original_initialize(attributes) @@ -40,7 +40,15 @@ def initialize(attributes = nil) WashOut::Param.send :include, WashoutBuilder::Document::ComplexType -[WashOut::SOAPError, SOAPError].each do |exception_class| +if defined?(WashOut::Model) + WashOut::Model.class_eval do + def wash_out_param_name(*args) + return name.underscore + end + end +end + +WashoutBuilder::Type.get_fault_classes.each do |exception_class| exception_class.class_eval do extend WashoutBuilder::Document::VirtusModel include Virtus.model @@ -83,7 +91,7 @@ def self.parse_builder_def(soap_config, definition) WashOut::Param.new(soap_config, name, opt) end end - end + end end diff --git a/lib/washout_builder/document/generator.rb b/lib/washout_builder/document/generator.rb index dad2b86..71a3f8d 100644 --- a/lib/washout_builder/document/generator.rb +++ b/lib/washout_builder/document/generator.rb @@ -27,7 +27,7 @@ def service end def service_description - config.description + config.respond_to?(:description) ? config.description : nil end def operations @@ -75,16 +75,16 @@ def complex_types def fault_types defined = soap_actions.select{|operation, formats| !formats[:raises].blank? } - defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.select { |x| x.is_a?(Class) && (x.ancestors.include?(WashOut::SOAPError) || x.ancestors.include?(SOAPError) ) } unless defined.blank? + defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.select { |x| (x.is_a?(Class) && x.ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present?) || (x.is_a?(Class) && WashoutBuilder::Type.get_fault_classes.include?(x)) } unless defined.blank? fault_types = [] if defined.blank? - defined = [WashOut::SOAPError] + defined = [WashoutBuilder::Type.get_fault_classes.first] else - defined << WashOut::SOAPError + defined << WashoutBuilder::Type.get_fault_classes.first end defined.each{ |exception_class| exception_class.get_fault_class_ancestors( fault_types, true)} unless defined.blank? complex_types = extract_nested_complex_types_from_exceptions(fault_types) - complex_types.delete_if{ |hash| fault_types << hash if hash[:fault].ancestors.include?(WashOut::SOAPError) || hash[:fault].ancestors.include?(SOAPError) } unless complex_types.blank? + complex_types.delete_if{ |hash| fault_types << hash if (hash[:fault].is_a?(Class) && hash[:fault].ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present?) || (hash[:fault].is_a?(Class) && WashoutBuilder::Type.get_fault_classes.include?(hash[:fault])) } unless complex_types.blank? fault_types = fault_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless fault_types.blank? complex_types = complex_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless complex_types.blank? [fault_types, complex_types] diff --git a/lib/washout_builder/engine.rb b/lib/washout_builder/engine.rb index 0c42c6f..4333cfd 100644 --- a/lib/washout_builder/engine.rb +++ b/lib/washout_builder/engine.rb @@ -5,8 +5,9 @@ class Engine < ::Rails::Engine match "/washout" => "washout_builder#all", :via => :get, :format => false end if app.config.wash_out[:catch_xml_errors] - app.config.middleware.insert_after 'ActionDispatch::ShowExceptions', WashOut::Middlewares::Catcher + app.config.middleware.insert_after 'ActionDispatch::ShowExceptions', WashOut::Middleware if defined?(WashOut::Middleware) + app.config.middleware.insert_after 'ActionDispatch::ShowExceptions', WashOut::Middlewares::Catcher if defined?(WashOut::Middlewares::Catcher) end end - end +end end diff --git a/lib/washout_builder/type.rb b/lib/washout_builder/type.rb index 55d6c91..b4ad96f 100644 --- a/lib/washout_builder/type.rb +++ b/lib/washout_builder/type.rb @@ -13,5 +13,14 @@ class Type "int" ] + def self.get_fault_classes + faults = [] + faults << WashOut::SOAPError if defined?(WashOut::SOAPError) + faults << WashOut::Dispatcher::SOAPError if defined?(WashOut::Dispatcher::SOAPError) + faults << SOAPError if defined?(SOAPError) + return faults + end + + end end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 76354ae..adc5fdd 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.11.0" + VERSION = "0.11.1" end diff --git a/washout_builder.gemspec b/washout_builder.gemspec index 01bd348..4a4813a 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.9.0") + s.add_dependency("wash_out", ">= 0.9.1") s.add_dependency("virtus", ">= 1.0.0") end