Skip to content

Commit

Permalink
Merge branch 'release/v0.11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Dec 19, 2013
2 parents a7cc872 + 8b70d65 commit d605798
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ Here is an example :
:description => "some description about this method to show in the documentation"


The exception classes used <b>must inherit</b> from <tt>WashOut::SOAPError</tt>, 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 <b>must inherit</b> from <tt>WashOut::Dispatcher::SOAPError</tt>, 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
Expand All @@ -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]
Expand All @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/washout_builder_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -83,7 +91,7 @@ def self.parse_builder_def(soap_config, definition)
WashOut::Param.new(soap_config, name, opt)
end
end
end
end

end

Expand Down
10 changes: 5 additions & 5 deletions lib/washout_builder/document/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def service
end

def service_description
config.description
config.respond_to?(:description) ? config.description : nil
end

def operations
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions lib/washout_builder/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions lib/washout_builder/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/washout_builder/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WashoutBuilder
VERSION = "0.11.0"
VERSION = "0.11.1"
end
2 changes: 1 addition & 1 deletion washout_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d605798

Please sign in to comment.