From dfe3bc9bedf04d468da61fc37c5fe07a8d579560 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 10 Dec 2013 19:38:54 +0200 Subject: [PATCH] added virtus as dependency for using custom exceptions --- Gemfile | 2 +- app/helpers/washout_builder_helper.rb | 33 ++++++++++++--------------- lib/washout_builder.rb | 10 ++++---- lib/washout_builder/version.rb | 2 +- washout_builder.gemspec | 1 + 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index c456d86..132b668 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gemspec gem 'wash_out', git: 'git://github.com/inossidabile/wash_out.git' - +gem 'virtus' gem 'wasabi' gem 'savon', '>= 2.0.0' gem 'httpi', :git => 'git://github.com/savonrb/httpi.git' diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index c751c12..b7e9e86 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -96,8 +96,8 @@ def get_complex_types(map) def get_fault_types_names(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.class.ancestors.include?(WashOut::SOAPError) } unless defined.blank? - defined.map{|item| item.class.to_s }.sort_by { |name| name.downcase }.uniq unless defined.blank? + defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.select { |x| x.ancestors.include?(WashOut::SOAPError) } unless defined.blank? + defined.map{|item| item.to_s }.sort_by { |name| name.downcase }.uniq unless defined.blank? end def get_soap_action_names(map) @@ -154,29 +154,26 @@ def create_html_fault_types_details(xml, map) end def create_html_fault_type(xml, param) - if param.class.ancestors.include?(WashOut::SOAPError) - xml.h3 "#{param.class}" - xml.a("name" => "#{param.class}") {} + # if param.class.ancestors.include?(WashOut::SOAPError) + xml.h3 "#{param}" + xml.a("name" => "#{param}") {} xml.ul("class" => "pre") { - - - param.class.accessible_attributes.each do |attribute| - if attribute!="code" && attribute != "message" && attribute!= 'backtrace' - attribute_class = param.send(attribute).class.name.downcase + 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_class) || attribute_class == "nilclass" - pre << "#{attribute_class == "nilclass" ? "string" : attribute_class } #{attribute}" + if WashoutBuilder::Type::BASIC_TYPES.include?(attribute_type) || attribute_type == "nilclass" + pre << "#{attribute_type == "nilclass" ? "string" : attribute_type } #{attribute}" else - pre << "#{attribute.class.name} #{attribute}" + pre << "#{attribute_type} #{attribute}" end } end end - xml.li { |pre| pre << "integer code" } - xml.li { |pre| pre << "string message" } xml.li { |pre| pre << "string backtrace" } } - end + # end end def create_html_public_methods(xml, map) @@ -290,12 +287,12 @@ def create_html_public_method(xml, operation, formats) faults = formats[:raises] faults = [formats[:raises]] if !faults.is_a?(Array) - faults = faults.select { |x| x.class.ancestors.include?(WashOut::SOAPError) } + faults = faults.select { |x| x.ancestors.include?(WashOut::SOAPError) } unless faults.blank? xml.p "Exceptions:" xml.ul { faults.each do |p| - xml.li("class" => "pre"){ |y| y<< " #{p.class.to_s}" } + xml.li("class" => "pre"){ |y| y<< " #{p.to_s}" } end } end diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index 979331d..d810b5e 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -1,5 +1,5 @@ require 'wash_out' - +require 'virtus' require 'washout_builder/soap' require 'washout_builder/engine' require 'washout_builder/dispatcher' @@ -25,10 +25,12 @@ def wash_out(controller_name, options={}) -WashOut::SOAPError.send :include, ActiveModel::MassAssignmentSecurity if defined?(WashOut::SOAPError) && defined?(ActiveModel::MassAssignmentSecurity) - - +WashOut::SOAPError.send :include, Virtus.model +WashOut::SOAPError.class_eval do + attribute :code, Integer + attribute :message, String +end ActionController::Base.class_eval do diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 50c4ebb..cd76389 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.8.12" + VERSION = "0.9.0" end diff --git a/washout_builder.gemspec b/washout_builder.gemspec index fc2e92b..cd49a69 100644 --- a/washout_builder.gemspec +++ b/washout_builder.gemspec @@ -17,4 +17,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency("nori", ">= 2.0.0") s.add_dependency("wash_out", ">= 0.10.0.beta.1") + s.add_dependency("virtus", ">= 1.0.0") end