Skip to content

Commit

Permalink
Merge branch 'release/v0.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed May 27, 2014
2 parents 8c35dde + eb59bdf commit 554a564
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 98 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ gemspec


gem 'wash_out', git: 'git://github.com/inossidabile/wash_out.git'
gem 'virtus'
gem 'wasabi'
gem 'savon'
gem 'httpi'
Expand Down
1 change: 0 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ The way WashOut is used is not modified, it just extends its functionality by ge
1. {Ruby 1.9.x or Ruby 2.0.x}[http://www.ruby-lang.org]
2. {Ruby on Rails}[http://rubyonrails.org].
3. {WashOut Gem version >= 0.9.1}[https://github.com/inossidabile/wash_out]
4. {Virtus Gem}[https://github.com/solnic/virtus]

= Compatibility

Expand Down
21 changes: 2 additions & 19 deletions lib/washout_builder.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
require 'wash_out'
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/exception_model'
require 'washout_builder/document/generator'
require 'washout_builder/type'
require 'washout_builder/version'



Virtus::InstanceMethods::Constructor.class_eval do
alias_method :original_initialize,:initialize
def initialize(attributes = nil)
if WashoutBuilder::Type.valid_fault_class?(self.class)
attributes = {:message => attributes} unless attributes.is_a?(Hash)
end
original_initialize(attributes)
end
end


WashOut::Param.send :include, WashoutBuilder::Document::ComplexType


WashoutBuilder::Type.get_fault_classes.each do |exception_class|
exception_class.class_eval do
extend WashoutBuilder::Document::VirtusModel
include Virtus.model
attribute :code, Integer
attribute :message, String
attribute :backtrace, String
extend WashoutBuilder::Document::ExceptionModel
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module WashoutBuilder
module Document
module VirtusModel
module ExceptionModel
extend ActiveSupport::Concern
include WashoutBuilder::Document::SharedComplexType

Expand Down Expand Up @@ -56,22 +56,47 @@ def get_virtus_member_type_primitive(attr_details)
complex_class
end



def get_exception_attributes
attrs = self.instance_methods.find_all do |method|
method != :== &&
method != :! &&
self.instance_methods.include?(:"#{method}=")
end
attrs.concat(["message", "backtrace"])
end


def get_virtus_model_structure
attribute_set.inject({}) {|h, elem| h["#{elem.name}"]= { :primitive => "#{elem.primitive}", :member_type => elem.options[:member_type].nil? ? nil: elem.options[:member_type].primitive }; h }
h = {}
get_exception_attributes.each do |method_name|
primitive_type = case method_name.to_s.downcase
when "code"
"integer"
when "message", "backtrace"
"string"
else
"string"
end
h["#{method_name}"]= {
:primitive => "#{primitive_type}",
:member_type => nil
}
end
return h
end


def self.extract_nested_complex_types(complex_class, complex_types)
unless complex_class.nil?
param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
if param_class.present? && param_class.ancestors.include?(Virtus::Model::Core)
param_class.send :extend, WashoutBuilder::Document::VirtusModel
param_class.get_fault_class_ancestors( complex_types)
elsif param_class.present? && !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
unless complex_class.nil?
param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
if param_class.present? && WashoutBuilder::Type.valid_fault_class?(param_class)
param_class.send :extend, WashoutBuilder::Document::ExceptionModel
param_class.get_fault_class_ancestors( complex_types)
elsif param_class.present? && !WashoutBuilder::Type.valid_fault_class?(param_class)
raise RuntimeError, "Non-existent use of `#{param_class}` type name or this class does not inherit from SoapError. Consider using classified types that include SoapError for exception classes."
end
end
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/washout_builder/document/generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./virtus_model"
require_relative "./exception_model"
module WashoutBuilder
module Document
class Generator
Expand Down Expand Up @@ -117,7 +117,7 @@ def extract_nested_complex_types_from_exceptions(fault_types)
fault_types.each do |hash|
hash[:structure].each do |attribute, attr_details|
complex_class = hash[:fault].get_virtus_member_type_primitive(attr_details)
WashoutBuilder::Document::VirtusModel.extract_nested_complex_types(complex_class, complex_types)
WashoutBuilder::Document::ExceptionModel.extract_nested_complex_types(complex_class, complex_types)
end
end
complex_types
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.12.4"
VERSION = "0.13.0"
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class SOAPError < WashOut::Dispatcher::SOAPError

end

describe WashoutBuilder::Document::VirtusModel do
describe WashoutBuilder::Document::ExceptionModel do

let(:subject) { SOAPError}



it "gets the strcuture" do
subject.get_virtus_model_structure.should eq({"code"=>{:primitive=>"Integer", :member_type=>nil}, "message"=>{:primitive=>"String", :member_type=>nil}, "backtrace"=>{:primitive=>"String", :member_type=>nil}})
subject.get_virtus_model_structure.should eq({"code"=>{:primitive=>"integer", :member_type=>nil}, "message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}})
end

it "gets the member type for arrays" do
Expand All @@ -29,7 +29,7 @@ class SOAPError < WashOut::Dispatcher::SOAPError


it "gets the strcuture" do
subject.remove_fault_type_inheritable_elements(["code"]).should eq({ "message"=>{:primitive=>"String", :member_type=>nil}, "backtrace"=>{:primitive=>"String", :member_type=>nil}})
subject.remove_fault_type_inheritable_elements(["code"]).should eq({ "message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}})
end

end
3 changes: 0 additions & 3 deletions spec/lib/washout_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,6 @@ def bad

end

it "intanstiates correctly a custom exception" do
soap_exception.attributes.should eq({:code=>error_code, :message=>error_message, :backtrace=>nil})
end
end


Expand Down
7 changes: 0 additions & 7 deletions spec/support/exceptions/another_exception.rb

This file was deleted.

15 changes: 0 additions & 15 deletions spec/support/exceptions/base_exception.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/support/exceptions/custom2.rb

This file was deleted.

8 changes: 0 additions & 8 deletions spec/support/exceptions/ex_model.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/support/exceptions/name_mod.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/support/exceptions/name_model.rb

This file was deleted.

8 changes: 0 additions & 8 deletions spec/support/exceptions/value_object_model.rb

This file was deleted.

1 change: 0 additions & 1 deletion washout_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ Gem::Specification.new do |s|
s.test_files = s.files.grep(/^(spec)/)
s.require_paths = ["lib"]
s.add_runtime_dependency 'wash_out', '~> 0.9', '>= 0.9.1'
s.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.0'
end

0 comments on commit 554a564

Please sign in to comment.