Skip to content

Commit

Permalink
Merge branch 'release/v0.9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Dec 11, 2013
2 parents 68a18e4 + d9ea9bd commit 7a4f0a5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 36 deletions.
133 changes: 103 additions & 30 deletions app/helpers/washout_builder_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def get_class_ancestors(param,class_name, defined)
bool_the_same = false
param_class = class_name.is_a?(Class) ? class_name : class_name.constantize rescue nil
unless param_class.nil?
ancestors = (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" }
unless ancestors.blank?
ancestor_structure = { ancestors[0].to_s.downcase => ancestors[0].columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } }
ancestor_object = WashOut::Param.parse_def(@soap_config,ancestor_structure)[0]
bool_the_same = same_structure_as_ancestor?(param, ancestor_object)
unless bool_the_same
top_ancestors = get_class_ancestors(ancestor_class, defined)
defined << {:class =>ancestor_class.to_s, :obj =>ancestor_object , :ancestors => top_ancestors }
ancestors = (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" }
unless ancestors.blank?
ancestor_structure = { ancestors[0].to_s.downcase => ancestors[0].columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } }
ancestor_object = WashOut::Param.parse_def(@soap_config,ancestor_structure)[0]
bool_the_same = same_structure_as_ancestor?(param, ancestor_object)
unless bool_the_same
top_ancestors = get_class_ancestors(ancestor_class, defined)
defined << {:class =>ancestor_class.to_s, :obj =>ancestor_object , :ancestors => top_ancestors }
end
end
end
ancestors unless bool_the_same
ancestors unless bool_the_same
end
end

Expand Down Expand Up @@ -94,10 +94,74 @@ def get_complex_types(map)
defined.sort_by { |hash| hash[:class].downcase }.uniq unless defined.blank?
end

def get_fault_types_names(map)

def remove_fault_type_inheritable_elements(param, keys)
get_virtus_model_structure(param).delete_if{|key,value| keys.include?(key) }
end


def same_fault_structure_as_ancestor?(param, ancestor)
param_structure = get_virtus_model_structure(param)
ancestor_structure = get_virtus_model_structure(ancestor)
if param_structure.keys == ancestor_structure.keys
return true, get_virtus_model_structure(param)
else
return false, remove_fault_type_inheritable_elements(param, ancestor_structure.keys)
end
end




def get_fault_class_ancestors(fault, defined)

bool_the_same = false
unless fault.nil?
ancestors = (fault.ancestors - fault.included_modules).delete_if{ |x| x.to_s.downcase == fault.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "Exception" }
if ancestors.blank?
defined << {:fault => fault,:structure =>get_virtus_model_structure(fault) ,:ancestors => [] }
else
bool_the_same, fault_structure = same_fault_structure_as_ancestor?(fault, ancestors[0])
unless bool_the_same
defined << {:fault => fault,:structure =>fault_structure ,:ancestors => ancestors }
get_fault_class_ancestors(ancestors[0], defined)
end
end
ancestors unless bool_the_same
end
end

def get_virtus_model_structure(fault)
fault.attribute_set.inject({}) {|h, elem| h["#{elem.name}"]= { :primitive => "#{elem.primitive.to_s.downcase}", :options => elem.options }; h }
end


def get_fault_types(map)
defined = map.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) } unless defined.blank?
defined.map{|item| item.to_s }.sort_by { |name| name.downcase }.uniq unless defined.blank?
fault_types = []
defined << WashOut::SOAPError
defined.each{ |item| get_fault_class_ancestors(item, fault_types)} unless defined.blank?
fault_types = fault_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless fault_types.blank?
complex_types = []
fault_types.each do |hash|
hash[:structure].each do |attribute, attr_details|
if attr_details[:primitive] == "array" && !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:options][:member_type].primitive.to_s.downcase)
complex_class = attr_details[:options][:member_type].primitive
elsif !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive])
complex_class = attr_details[:primitive]
end

param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
if !param_class.nil? && param_class.ancestors.include?(Virtus::Model::Core)
complex_types << get_fault_class_ancestors(param_class, complex_types)
elsif !param_class.nil? && !param_class.ancestors.include?(Virtus::Model::Core)
raise RuntimeError, "Non-existent use of `#{param_class}` type name or this class does not use Virtus.model. Consider using classified types that include Virtus.mode for exception atribute types."
end

end
end
[fault_types, complex_types]
end

def get_soap_action_names(map)
Expand Down Expand Up @@ -145,33 +209,42 @@ def create_complex_type_html(xml, param, class_name, ancestors)
end
end

def create_html_fault_types_details(xml, map)
defined = map.select{|operation, formats| !formats[:raises].blank? }
unless defined.blank?
defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.sort_by { |item| item.class.to_s.downcase }.uniq
defined.each { |fault| create_html_fault_type(xml, fault) }
def create_html_fault_types_details(xml, fault_types)
unless fault_types.blank?

fault_types.each { |hash|
create_html_virtus_model_type(xml, hash[:fault],hash[:structure], hash[:ancestors]) unless hash.blank?
}
end
end

def create_html_fault_type(xml, param)
if param.is_a?(Class) && param.ancestors.include?(WashOut::SOAPError)
xml.h3 "#{param}"



def create_html_virtus_model_type(xml, param, fault_structure, ancestors)
if param.is_a?(Class)
xml.h3 { |pre| pre << "#{param} #{ancestors.blank? ? "" : "<small>(extends <a href='##{ancestors[0].to_s.classify}'>#{ancestors[0].to_s.classify}</a>)</small>" } " }
xml.a("name" => "#{param}") {}
xml.ul("class" => "pre") {
fault_structure = param.attribute_set.inject({}) {|h, elem| h["#{elem.name}"]= "#{elem.primitive.to_s.downcase}"; h }


fault_structure.each do |attribute, attribute_type|
if attribute!= 'backtrace'
xml.li { |pre|
if WashoutBuilder::Type::BASIC_TYPES.include?(attribute_type) || attribute_type == "nilclass"
pre << "<span class='blue'>#{attribute_type == "nilclass" ? "string" : attribute_type }</span>&nbsp;<span class='bold'>#{attribute}</span>"
fault_structure.each do |attribute, attr_details|
xml.li { |pre|
if WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive]) || attr_details[:primitive] == "nilclass"
pre << "<span class='blue'>#{attr_details[:primitive] == "nilclass" ? "string" : attr_details[:primitive] }</span>&nbsp;<span class='bold'>#{attribute}</span>"

else
if attr_details[:primitive] == "array"
attr_primitive = attr_details[:options][:member_type].primitive.to_s

attr_primitive = WashoutBuilder::Type::BASIC_TYPES.include?(attr_primitive.downcase) ? attr_primitive.downcase : attr_primitive
pre << "<a href='##{attr_primitive}'><span class='lightBlue'>Array of #{attr_primitive}</span></a>&nbsp;<span class='bold'>#{attribute}</span>"
else
pre << "<a href='##{attribute_type}'><span class='lightBlue'>#{attribute_type}</span></a>&nbsp;<span class='bold'>#{attribute}</span>"
pre << "<a href='##{attr_details[:primitive] }'><span class='lightBlue'>#{attr_details[:primitive]}</span></a>&nbsp;<span class='bold'>#{attribute}</span>"
end
}
end
end
}
end
xml.li { |pre| pre << "<span class='blue'>string</span>&nbsp;<span class='bold'>backtrace</span>" }
}
end
end
Expand Down
11 changes: 7 additions & 4 deletions app/views/wash_with_html/doc.builder
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
end

end
@fault_types = get_fault_types_names(@map)
@fault_types, @fault_complex_types = get_fault_types(@map)
unless @fault_types.blank?
xml.p "Fault Types: "

xml.ul do
@fault_types.each do |name|
xml.li { |y| y << "<a href='##{name}'><span class='pre'>#{name}</span></a>" }
@fault_types.each do |hash|
xml.li { |y| y << "<a href='##{hash[:fault].to_s}'><span class='pre'>#{hash[:fault].to_s}</span></a>" }
end
end
end
Expand All @@ -89,9 +89,12 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
xml.h2 "Complex types:"
create_html_complex_types(xml, @complex_types)
end
unless @fault_complex_types.blank?
create_html_fault_types_details(xml, @fault_complex_types)
end
unless @fault_types.blank?
xml.h2 "Fault types:"
create_html_fault_types_details(xml, @map)
create_html_fault_types_details(xml, @fault_types)
end
unless @methods.blank?
xml.h2 "Public methods:"
Expand Down
3 changes: 2 additions & 1 deletion lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ def wash_out(controller_name, options={})



WashOut::SOAPError.send :include, Virtus.model

WashOut::SOAPError.class_eval do
include Virtus.model
attribute :code, Integer
attribute :message, String
attribute :backtrace, String
end


Expand Down
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.9.1"
VERSION = "0.9.2"
end

0 comments on commit 7a4f0a5

Please sign in to comment.