Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed May 23, 2014
2 parents 51818d7 + 839f7cb commit 8cbdd37
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'virtus'
require 'washout_builder/soap'
require 'washout_builder/engine'
require 'washout_builder/document/shared_complex_type'
require 'washout_builder/document/complex_type'
require 'washout_builder/document/virtus_model'
require 'washout_builder/document/generator'
Expand Down
3 changes: 2 additions & 1 deletion lib/washout_builder/document/complex_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module WashoutBuilder
module Document
module ComplexType
extend ActiveSupport::Concern
include WashoutBuilder::Document::SharedComplexType


def get_complex_class_name(defined = [])
Expand Down Expand Up @@ -66,7 +67,7 @@ def get_ancestors(class_name)
if param_class.nil?
return nil
else
(param_class.ancestors - param_class.included_modules).delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" }
get_complex_type_ancestors(param_class, ["ActiveRecord::Base", "Object", "BasicObject", "WashOut::Type" ])
end
end

Expand Down
49 changes: 33 additions & 16 deletions lib/washout_builder/document/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def operations
soap_actions.map { |operation, formats| operation }
end

def sort_fault_types(types)
types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq {|hash| hash[:fault] } unless types.blank?
def sort_complex_types(types, type)
types.sort_by { |hash| hash[type.to_sym].to_s.downcase }.uniq {|hash| hash[type.to_sym] } unless types.blank?
end


Expand Down Expand Up @@ -70,7 +70,7 @@ def complex_types
(input_types + output_types).each do |p|
defined.concat(p.get_nested_complex_types(config, defined))
end
defined.sort_by { |hash| hash[:class].to_s.downcase }.uniq{|hash| hash[:class] } unless defined.blank?
defined = sort_complex_types(defined, "class")
end


Expand All @@ -79,25 +79,42 @@ def actions_with_exceptions
end

def exceptions_raised
actions = actions_with_exceptions
faults= actions.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 actions.blank?
if faults.blank?
faults = [WashoutBuilder::Type.get_fault_classes.first]
actions_with_exceptions.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten
end

def fault_classes
WashoutBuilder::Type.get_fault_classes
end

def has_ancestor_fault?(fault_class)
fault_class.ancestors.detect{ |fault| fault_classes.include?(fault) }.present?
end

def valid_fault_class?(fault)
fault.is_a?(Class) && ( has_ancestor_fault?(fault) || fault_classes.include?(fault))
end

def filter_exceptions_raised
exceptions_raised.select { |x| valid_fault_class?(x) } unless actions_with_exceptions.blank?
end

def get_complex_fault_types(fault_types)
defined = filter_exceptions_raised
if defined.blank?
defined = [fault_classes.first]
else
faults << WashoutBuilder::Type.get_fault_classes.first
defined << fault_classes.first
end
faults
defined.each{ |exception_class| exception_class.get_fault_class_ancestors( fault_types, true)} unless defined.blank?
fault_types
end


def fault_types
defined = exceptions_raised
fault_types = []
defined.each{ |exception_class| exception_class.get_fault_class_ancestors( fault_types, true)} unless defined.blank?
fault_types = get_complex_fault_types([])
complex_types = extract_nested_complex_types_from_exceptions(fault_types)
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 = sort_fault_types(fault_types)
complex_types = sort_fault_types(complex_types)
complex_types.delete_if{ |hash| fault_types << hash if valid_fault_class?(hash[:fault]) } unless complex_types.blank?
fault_types = sort_complex_types(fault_types, "fault")
complex_types = sort_complex_types(complex_types, "fault")
[fault_types, complex_types]
end

Expand Down
11 changes: 11 additions & 0 deletions lib/washout_builder/document/shared_complex_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module WashoutBuilder
module Document
module SharedComplexType

def get_complex_type_ancestors(class_name, array)
(class_name.ancestors - class_name.included_modules).delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || array.include?(x.to_s) }
end

end
end
end
7 changes: 6 additions & 1 deletion lib/washout_builder/document/virtus_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module WashoutBuilder
module Document
module VirtusModel
extend ActiveSupport::Concern
include WashoutBuilder::Document::SharedComplexType

def self.included(base)
base.send :include, WashoutBuilder::Document::SharedComplexType
end

def get_fault_class_ancestors( defined, debug = false)
bool_the_same = false
Expand All @@ -21,7 +26,7 @@ def fault_without_inheritable_elements(ancestors)
end

def fault_ancestors
(self.ancestors - self.included_modules).delete_if{ |x| x.to_s.downcase == self.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "Exception" }
get_complex_type_ancestors(self, ["ActiveRecord::Base", "Object", "BasicObject", "Exception" ])
end

def fault_ancestor_hash( structure, ancestors)
Expand Down

0 comments on commit 8cbdd37

Please sign in to comment.