Skip to content

Commit

Permalink
Merge branch 'release/v0.12.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed May 26, 2014
2 parents 6f61c83 + 6fc7cdc commit 2eb7d9a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 54 deletions.
12 changes: 1 addition & 11 deletions app/controllers/washout_builder/washout_builder_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WashoutBuilder::WashoutBuilderController < ActionController::Base
def all
route = params[:name].present? ? controller_is_a_service?(params[:name]) : nil
if route.present?
@document = initialize_service_generator(route)
@document = WashoutBuilder::Document::Generator.new(route.defaults[:controller])
render :template => "wash_with_html/doc", :layout => false,
:content_type => 'text/html'
else
Expand All @@ -17,16 +17,6 @@ def all
private


def initialize_service_generator(route)
controller_class_name = controller_class(route.defaults[:controller])
WashoutBuilder::Document::Generator.new(
:config => controller_class_name.soap_config,
:service_class => controller_class_name,
:soap_actions => controller_class_name.soap_actions
)
end


def all_services
@map_controllers = map_controllers
@services = @map_controllers.blank? ? [] : @map_controllers.map do |controller_name|
Expand Down
2 changes: 1 addition & 1 deletion lib/washout_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Virtus::InstanceMethods::Constructor.class_eval do
alias_method :original_initialize,:initialize
def initialize(attributes = nil)
if self.class.ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present? || WashoutBuilder::Type.get_fault_classes.include?(self.class)
if WashoutBuilder::Type.valid_fault_class?(self.class)
attributes = {:message => attributes} unless attributes.is_a?(Hash)
end
original_initialize(attributes)
Expand Down
2 changes: 1 addition & 1 deletion lib/washout_builder/document/complex_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def remove_type_inheritable_elements( keys)

def fix_descendant_wash_out_type(config, complex_class)
param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
if !param_class.nil? && param_class.ancestors.include?(WashOut::Type) && !map[0].nil?
if param_class.present? && param_class.ancestors.include?(WashOut::Type) && map[0].present?
descendant = WashOut::Param.parse_builder_def(config, param_class.wash_out_param_map)[0]
self.name = descendant.name
self.map = descendant.map
Expand Down
66 changes: 26 additions & 40 deletions lib/washout_builder/document/generator.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
require_relative "./virtus_model"
module WashoutBuilder
module Document
class Generator

@attrs = [:soap_actions, :config, :service_class]
@attrs = [:soap_actions, :config, :controller_name]

attr_reader *@attrs
attr_accessor *@attrs

def initialize(attrs = {})
self.config = attrs[:config]
self.service_class = attrs[:service_class]
self.soap_actions = attrs[:soap_actions]
def initialize(controller)
controller_class_name = controller_class(controller)
self.config =controller_class_name.soap_config
self.soap_actions = controller_class_name.soap_actions
self.controller_name = controller
end

def namespace
config.namespace
config.respond_to?(:namespace) ? config.namespace : nil
end


def controller_class(controller)
"#{controller}_controller".camelize.constantize
end

def endpoint
namespace.gsub("/wsdl", "/action")
namespace.blank? ? nil : namespace.gsub("/wsdl", "/action")
end

def service
service_class.name.underscore.gsub("_controller", "").camelize
controller_name.blank? ? nil : controller_name.camelize
end

def service_description
Expand All @@ -35,7 +40,7 @@ def operations
end

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?
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 @@ -75,35 +80,24 @@ def complex_types


def actions_with_exceptions
soap_actions.select{|operation, formats| !formats[:raises].blank? }
soap_actions.select{|operation, formats| !formats[:raises].blank? }
end

def exceptions_raised
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))
actions_with_exceptions.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten
end



def filter_exceptions_raised
exceptions_raised.select { |x| valid_fault_class?(x) } unless actions_with_exceptions.blank?
exceptions_raised.select { |x| WashoutBuilder::Type.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]
defined = [WashoutBuilder::Type.get_fault_classes.first]
else
defined << fault_classes.first
defined << WashoutBuilder::Type.get_fault_classes.first
end
defined.each{ |exception_class| exception_class.get_fault_class_ancestors( fault_types, true)} unless defined.blank?
fault_types
Expand All @@ -112,7 +106,7 @@ def get_complex_fault_types(fault_types)
def fault_types
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 valid_fault_class?(hash[:fault]) } unless complex_types.blank?
complex_types.delete_if{ |hash| fault_types << hash if WashoutBuilder::Type.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]
Expand All @@ -123,20 +117,12 @@ 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)
unless complex_class.nil?
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)
param_class.send :extend, WashoutBuilder::Document::VirtusModel
param_class.get_fault_class_ancestors( 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
WashoutBuilder::Document::VirtusModel.extract_nested_complex_types(complex_class, complex_types)
end
end
complex_types
end




Expand Down
12 changes: 12 additions & 0 deletions lib/washout_builder/document/virtus_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def get_virtus_model_structure
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
end

end
end
end
9 changes: 9 additions & 0 deletions lib/washout_builder/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def self.get_fault_classes
return faults
end


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

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


end
end
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.2"
VERSION = "0.12.3"
end

0 comments on commit 2eb7d9a

Please sign in to comment.