Skip to content

Commit

Permalink
Merge branch 'feature/track-exception-attributes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed May 27, 2014
2 parents d384397 + e1f1298 commit 9938beb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
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 use Virtus.model. Consider using classified types that include Virtus.mode for exception atribute types."
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
2 changes: 1 addition & 1 deletion washout_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ 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'
#s.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.0'
end

0 comments on commit 9938beb

Please sign in to comment.